我正在使用mybatis-3.2.8.jar和JDK 1.6.0_45。在MyBatis中,是否有任何解決方案在設置空參數時不添加jdbcType?
源表被稱爲emp
:
> EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO SHORTCUT
>
> 7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30 null
和SQL是這樣的:
insert into emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, SHORTCUT)
values
(#{EMPNO},#{ENAME},#{JOB},#{MGR},#{HIREDATE},#{SAL},#{COMM},#{DEPTNO},#{SHORTCUT});
我使用這個SQL逐行。選擇1行然後再次插入。或者認爲桌子只有一排。
然後,我面臨着這樣的錯誤:
org.apache.ibatis.exceptions.PersistenceException:
#### Error updating database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #7 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=insert into TB_ODS_EMP2(EMPNO,ENAME,JOB,MGR;BEGIN-OF-STATEMENT;<grant>, DRIVER=4.12.55
#### The error may involve pdss5.hs.hdw.ETLTargetMapper.insertTargetTable-Inline
#### The error occurred while setting parameters
#### SQL: insert into TB_ODS_EMP2(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO,SHORTCUT) values(?,?,?,?,?,?,?,?,?) Call getNextException to see the cause
#### Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #7 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=insert into TB_ODS_EMP2(EMPNO,ENAME,JOB,MGR;BEGIN-OF-STATEMENT;<grant>, DRIVER=4.12.55
我的團長不想使用jdbyTYPE
這樣的:
insert into emp
(#{EMPNO},#{ENAME},#{JOB},#{MGR},#{HIREDATE},#{SAL},#{COMM},#{DEPTNO},`#{SHORTCUT,jdbcTYPE=VARCHAR}`)
......
在MyBatis的,是有不添加時jdbc類型的任何解決方案設置null參數?
我想加入jdbcTYPE=VARCHAR
是不夠好,但我主要討厭它(也許...)。
它是用於Oracle的DB2。如果Oracle到Oracle,沒有遇到錯誤。我不知道爲什麼。 :-( – gadiz