Error setting null for parameter #4 with JdbcType OTHER 或者 java.sql.SQLException: 无效的列类型: 1111

mybatis+oracle 插入或者批量插入值为null的时候报这个错误  Error setting null for parameter #4 with JdbcType OTHER  或者java.sql.SQLException: 无效的列类型: 1111

解决方法在值为null的字段上指定jdbcType即可

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0.servicelevel', mode=IN, javaType=class java.lang.Short, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 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:92)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
	at com.sun.proxy.$Proxy52.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:93)
	at com.sun.proxy.$Proxy58.insertList(Unknown Source)
	at cm.orc.dao.CirCuitMapperTest.testInsertList(CirCuitMapperTest.java:30)
	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:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_item_0.servicelevel', mode=IN, javaType=class java.lang.Short, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
	at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:94)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:88)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	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:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
	... 69 more
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:63)
	at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
	... 82 more
Caused by: java.sql.SQLException: 无效的列类型: 1111
	at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3950)
	at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:4559)
	at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:4541)
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.setNull(OraclePreparedStatementWrapper.java:1283)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.setNull(DruidPooledPreparedStatement.java:266)
	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:498)
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	at com.sun.proxy.$Proxy70.setNull(Unknown Source)
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:61)
	... 83 more

第一种解决方案就是在sql中加入类型;例如

Error setting null for parameter #4 with JdbcType OTHER 这个错误表示的就是第五个参数需要指定类型,加入类型即可

#{item.servicelevel,jdbcType=NUMERIC},

<insert id="insertList" >
    begin
    <foreach collection="list" item="item" index="index">
      INSERT INTO CIRCUIT VALUES (CIRCUIT_ID.nextval,
      #{item.version,jdbcType=NUMERIC},
      #{item.no,jdbcType=VARCHAR},
      #{item.name,jdbcType=VARCHAR},
      #{item.servicelevel,jdbcType=NUMERIC},
      #{item.status,jdbcType=NUMERIC},
      #{item.service,jdbcType=VARCHAR},
      #{item.updatetime,jdbcType=DATE},
      #{item.zctpid,jdbcType=NUMERIC},
      #{item.zcustomerid,jdbcType=NUMERIC},
      #{item.acustomerid,jdbcType=NUMERIC},
      #{item.amesite,jdbcType=VARCHAR},
      #{item.ameid,jdbcType=NUMERIC},
      #{item.aportid,jdbcType=NUMERIC},
      #{item.actpid,jdbcType=NUMERIC},
      #{item.zmesite,jdbcType=VARCHAR},
      #{item.zmeid,jdbcType=NUMERIC},
      #{item.zportid,jdbcType=NUMERIC},
      #{item.direction,jdbcType=NUMERIC},
      #{item.existsnc,jdbcType=NUMERIC},
      #{item.isrented,jdbcType=NUMERIC},
      #{item.opendate,jdbcType=DATE},
      #{item.otherno,jdbcType=VARCHAR},
      #{item.isgatherpm,jdbcType=NUMERIC},
      #{item.groupno,jdbcType=VARCHAR},
      #{item.targetuse,jdbcType=VARCHAR},
      #{item.trunkgroupid,jdbcType=NUMERIC},
      #{item.resrate,jdbcType=VARCHAR},
      #{item.ressynclog,jdbcType=VARCHAR},
      #{item.ressyncresult,jdbcType=NUMERIC},
      #{item.resid,jdbcType=VARCHAR},
      #{item.reserror,jdbcType=NUMERIC},
      #{item.isgatherctppm,jdbcType=NUMERIC},
      #{item.existsroute,jdbcType=NUMERIC},
      #{item.servicetype,jdbcType=VARCHAR},
      #{item.reslastsyntime,jdbcType=DATE},
      #{item.resaregionid,jdbcType=NUMERIC},
      #{item.reszregionid,jdbcType=NUMERIC},
      #{item.bizstatus,jdbcType=NUMERIC},
      #{item.statuslog,jdbcType=VARCHAR},
      #{item.vital,jdbcType=NUMERIC},
      #{item.notsla,jdbcType=NUMERIC},
      #{item.rescircuitstate,jdbcType=VARCHAR},
      #{item.resbizproperty,jdbcType=VARCHAR},
      #{item.vniid,jdbcType=VARCHAR},
      #{item.vniname,jdbcType=VARCHAR},
      #{item.timelimit,jdbcType=NUMERIC},
      #{item.vlan,jdbcType=NUMERIC},
      #{item.faultbill,jdbcType=NUMERIC},
      #{item.businessproperty,jdbcType=NUMERIC},
      #{item.manualcheckflag,jdbcType=NUMERIC});
      </foreach>
    end;
  </insert>

另一种方式就是在mybatis配置文件中添加配置:

<configuration>
<settings>
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
</configuration>

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误提示是因为在设置参数时,使用了不支持的JDBC类型,导致无法设置为null值。建议尝试使用其他JDBC类型或者修改配置属性来解决这个问题。同时,错误的原因是无效类型,可能需要检查数据库表结构和数据类型是否正确。 ### 回答2: "Error setting null for parameter"这个错误信息通常出现在程序运行时发现参数为null的情况,但是该参数不允许为null。这意味着程序在运行时无法取得所需的数据,导致程序无法正常运行。 这种错误通常是由于程序员在编写代码时,没有正确设置参数的默认值,导致程序无法正常运行。另外,该错误也可能是由于程序中的数据传输错误、数据类型不匹配、错误的参数顺序或参数个数不正确导致的。 要解决这个问题,我们可以采取以下几种方法: 1. 当发现出现“Error setting null for parameter”时,首先要检查程序中的参数是否正确设置,默认值是否已经初始化。如果未设置或初始化,则需要加以修复,修改代码后重新运行程序。 2. 检查程序中的数据传输,确保数据从一个地方传到另一个地方需要的参数个数和类型是正确的。如果数据不匹配,请修复代码并重新运行程序。 3. 检查程序中参数传递的顺序是否正确,对于多个参数的情况,参数顺序的错误可能会导致该错误的发生。如果参数顺序有问题,请修复代码后重新运行程序。 4. 对于参数个数不正确的情况,需要检查程序中是否有必要的参数传递,如果缺少必要参数,则需要修复代码后重新运行程序。 总之,如果出现“Error setting null for parameter”错误,需要仔细检查代码,确定并修复程序中的错误,保证程序正常运行。同时,程序员应当注意代码编写的规范,正确设置参数的默认值和数据类型,防止此类错误的发生。 ### 回答3: "Error setting null for parameter"是一个常见的错误提示信息,通常在使用数据库操作时出现。该错误发生的原因有很多种,但是大多数情况下,它与SQL语句中的参数有关。 首先,在执行SQL语句时,我们通常需要为其中的参数设定值。如果参数的值为null或者没有设置,就可能会出现这个错误信息。 其次,这个错误也可能与SQL语句中的参数类型有关。数据类型的不匹配也会导致该错误的出现。例如,如果SQL语句中的参数为字符串类型,但是在执行时却将null值或者其他类型的值传入,就会导致该错误的出现。 此外,该错误也可能与编程语言的实现有关。在某些编程语言中,当将null值传入方法或函数时,可能会导致该错误的出现。这通常是由于编程语言或框架在处理null值时遇到问题,导致出现该错误信息。 最后,解决该错误的方法取决于具体的情况。如果该错误与SQL语句中的参数有关,我们可以检查SQL语句的参数设置以及数据类型是否匹配。如果该错误与编程语言的实现有关,我们可以考虑使用一些技巧来处理null值,例如使用“if null”或“if empty”等条件判断语句。 总之,在遇到该错误时,我们应该先了解具体情况,并尝试寻找相应的解决方法,以便及时解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值