操作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或其它类型值。

 

posted @ 2019-08-30 18:05  Arebirth  阅读(17402)  评论(0编辑  收藏  举报