zoukankan      html  css  js  c++  java
  • 操作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或其它类型值。
  • 相关阅读:
    struts2重点——ValueStack和OGNL
    struts2基础——请求与响应、获取web资源
    struts2基础——最简单的一个例子
    servlet、filter、listener、interceptor之间的区别和联系
    服务器端组件
    自定义JSTL标签和函数库
    常见前端效果实现
    HTTP Cookie/Session
    获取动态SQL查询语句返回值(sp_executesql)
    WPF数据绑定
  • 原文地址:https://www.cnblogs.com/arebirth/p/11436432.html
Copyright © 2011-2022 走看看