解决方案:给参数指定jdbcType属性。
示例:
#{item,jdbcType=VARCHAR}
报错信息:
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:67)
at com.baomidou.mybatisplus.core.MybatisParameterHandler.setParameters(MybatisParameterHandler.java:213)
... 134 more
Caused by: java.sql.SQLException: Invalid column type: 1111
at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:4121)
at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:4208)
at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:4192)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setNull(OraclePreparedStatementWrapper.java:1010)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setNull(FilterChainImpl.java:3263)
at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setNull(FilterAdapter.java:1309)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setNull(FilterChainImpl.java:3260)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setNull(PreparedStatementProxyImpl.java:446)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.setNull(DruidPooledPreparedStatement.java:270)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:65)
报错信息:
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy150.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy153.page(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
at com.sun.proxy.$Proxy154.page(Unknown Source)
分析:
java.sql.SQLException: Invalid column type: 1111
这个报错是在at oracle.jdbc.driver.OracleStatement.getInternalType方法触发的,
在结合翻译 就是orcal不支持的字段类型:1111”。
在接着找报错信息,
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{........}
Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property.
报错的方法在 at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters。
查看mybatis源码:

接着看源码:

源码结合报错信息的parameterMapping输出,可以发现,我们插入的是一个空值,而且也没有指定这个插入字段类型(JdbcType),mybatis就给了一个默认类型

通过上面的源码分析,得出的就是报错信息的意思:
Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter.........Invalid column type: 1111
给第四个参数(参数类型为JdbcType OTHER==1111)赋了一个空值,这中情况下,orcal不支持参数的类型1111,
解决办法,不给空值,或者参数类型不能为1111,这不,mybatis给出了提示,尝试给参数不同的JdbcType,
查看业务代码sql #{item.CUST_ORDER_ID},果然没有指定JdbcType,
修改为#{item.CUST_ORDER_ID,jdbcType=VARCHAR},这样按理说问题就解决了
原文链接:https://blog.youkuaiyun.com/duzhe1991/article/details/126441988
文章讲述了在使用MyBatis时遇到关于Oracle数据库的Invalidcolumntype:1111错误,原因在于参数映射中未指定jdbcType且尝试插入空值。解决方法是为参数指定jdbcType,如VARCHAR,避免空值并确保列类型兼容。
3392

被折叠的 条评论
为什么被折叠?



