操作MyBatis引发Error setting null for parameter #X with JdbcType OTHER .无效的列类型

Posted arebirth

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了操作MyBatis引发Error setting null for parameter #X with JdbcType OTHER .无效的列类型相关的知识,希望对你有一定的参考价值。

再用MyBatis操作Oracle的时候,传入null值而引发的错误

异常信息:

org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #6 with JdbcType OTHER .
 Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: 
 java.sql.SQLException: 无效的列类型 ; 
 uncategorized SQLException for SQL []; SQL state [null]; error code [17004];
 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型

 

当我们用MyBatis操作数据库的时候传入null值,而且没有加入jdbcType类型的时候就会引发上述这种错误类型,

因为MyBatis不知道这个地方要传入什么什么参数

 

解决方案:

1.

单个配置
直接在后面加上 jdbcType=类型
#id,jdbcType=VARCHAR

2.

 全局配置

在MyBaits的核心配置文件里面进行配置

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

第二种配置方式官方是这样解释的:

Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers require specifying the column JDBC type but others work with generic values like NULL, VARCHAR or OTHER. 


当没有为参数提供特定的JDBC类型时,指定的jdbc类型为空。一些驱动程序需要指定列JDBC类型,但其他驱动程序使用NULL、VARCHAR或其它类型值。

 

以上是关于操作MyBatis引发Error setting null for parameter #X with JdbcType OTHER .无效的列类型的主要内容,如果未能解决你的问题,请参考以下文章

### The error occurred while setting parameters, MyBatis框架使用报错原因及解决办法

Mybatis Error attempting to get column 'xxx' from result set. Cause: java.sql.SQLDataExcepti

Mybatis Error attempting to get column 'xxx' from result set. Cause: java.sql.SQLDataExcepti

mybatis报错Error attempting to get column ‘id‘ from result set. Cause: org.postgresql.util.PSQLExcept

MyBatis 日志输出

记录并引发异常