今天出现这样一个错误
12:29:40.974 [main] DEBUG o.s.j.s.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '-4228', will now try the fallback translator
12:29:40.979 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [-4228];
--- The error occurred in sqlMap/ehrIndex.xml.
--- The error occurred while applying a parameter map.
--- Check the ehrIndex.insertEhrIndex-InlineParameterMap.
--- Check the parameter mapping for the 'flag' property.
--- Cause: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.50.152] 无法识别 JDBC 类型:0。 ERRORCODE=-4228, SQLSTATE=null; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in sqlMap/ehrIndex.xml.
--- The error occurred while applying a parameter map.
--- Check the ehrIndex.insertEhrIndex-InlineParameterMap.
--- Check the parameter mapping for the 'flag' property.
--- Cause: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.50.152] 无法识别 JDBC 类型:0。 ERRORCODE=-4228, SQLSTATE=null
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)
at org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:364)
at com.founder.dao.impl.EhrIndexDaoImpl.insertEhrIndex(EhrIndexDaoImpl.java:10)
at com.founder.service.impl.IntegrationHealthRecordServiceImpl.handleEhrIndex(IntegrationHealthRecordServiceImpl.java:143)
at com.founder.service.impl.IntegrationHealthRecordServiceImpl.invoke(IntegrationHealthRecordServiceImpl.java:68)
at com.founder.Launch.main(Launch.java:17)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in sqlMap/ehrIndex.xml.
--- The error occurred while applying a parameter map.
--- Check the ehrIndex.insertEhrIndex-InlineParameterMap.
--- Check the parameter mapping for the 'flag' property.
--- Cause: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.50.152] 无法识别 JDBC 类型:0。 ERRORCODE=-4228, SQLSTATE=null
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
at org.springframework.orm.ibatis.SqlMapClientTemplate$8.doInSqlMapClient(SqlMapClientTemplate.java:366)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
... 5 more
Caused by: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.50.152] 无法识别 JDBC 类型:0。 ERRORCODE=-4228, SQLSTATE=null
at com.ibm.db2.jcc.b.wc.a(wc.java:55)
at com.ibm.db2.jcc.b.wc.a(wc.java:102)
at com.ibm.db2.jcc.b.cb.i(cb.java:1219)
at com.ibm.db2.jcc.b.uk.b(uk.java:612)
at com.ibm.db2.jcc.b.uk.setNull(uk.java:584)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setNull(NewProxyPreparedStatement.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:70)
at $Proxy2.setNull(Unknown Source)
at com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:172)
at com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
... 9 more
原因在于flag这个属性数据库中是CHARACTER类型,而java代码中string类型,我把flag设为null,ibatis中又是这样写代码
insert into
EHR_INDEX(
INDEX_ID,EHR_ID,EHR_NAME,PARENT_ID,
FLAG,PERSON_ID,TYPE_ID,INDEX_SEQUENCE,
PIX_ID,NAME,AGE,EVENT_DATE,
EVENT_YEAR,EVENT_MONTH,DISEASE,DISEASE_NAME,
CREATE_DATE,CREATE_UNIT,CREATE_UNIT_NAME,CREATE_DEPT,
CREATOR,CREATOR_NAME,MODIFY_DATE,MODIFY_UNIT,
MODIFY_DEPT,MODIFIER,MODIFIER_NAME,MGMT_FLAG,
CREATOR_ID_NO
)
values(
#indexId#,#ehrId#,#ehrName#,#parentId#,
#flag#,#personId#,#typeId#,#indexSequence#,
#pixId#,#name#,#age#,#eventDate#,
#eventYear#,#eventMonth#,#disease#,#diseaseName#,
#createDate#,#createUnit#,#createUnitName#,#createDept#,
#creator#,#creatorName#,#modifyDate#,#modifyUnit#,
#modifyDept#,#modifier#,#modifierName#,#mgmtFlag#,
#creatorIdNo#
)
所以抱这样的错,关键在于代码不规范啊,解决办法在在ibatis中#flag#中加入类型处理,如#flag:char#