zoukankan      html  css  js  c++  java
  • UncategorizedSQLException Mybatis中jdbcType的作用

    使用MyBatis框架做更新操作时,在该字段需要更新的内容为空时,就会出现1111错误,也就是无效的列类型,这个时候你就要使用jdbcType。至于什么时候要使用到javaType我还没遇到过,而且我也没有听说过要使用javaType

    异常显示如下:

    Exception in thread "main" 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: 无效的列类型: 1111
    ; uncategorized SQLException for SQL []; SQL state [99999]; error code [17004]; 无效的列类型: 1111; nested exception is java.sql.SQLException: 无效的列类型: 1111

    mybatis insert空值报空值异常,但是在pl/sql不会提示错误,主要原因是mybatis无法进行转换,

    错误日志是在:org.apache.ibatis.type.BaseTypeHandler这个类的第17行打出的。

    if (parameter == null) {  
    
      if (jdbcType == null) {  
    
      try {  
    
      ps.setNull(i, JdbcType.OTHER.TYPE_CODE);  
    
      } catch (SQLException e) {  
    
      throw new TypeException("Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: " + e, e);  
    
      }  
    
      } else {  
    
      ps.setNull(i, jdbcType.TYPE_CODE);  
    
      }  
    
      } else {  
    
      setNonNullParameter(ps, i, parameter, jdbcType);  
    
      }  

    可以看出,是因为你传入的参数的字段为null对象无法获取对应的jdbcType类型,而报的错误。

    你只要在insert语句中insert的对象加上jdbcType就可以了,修改如下:

    #{menuTitle,jdbcType=VARCHAR}

  • 相关阅读:
    SQL SERVER 2005添加用户和编辑sa
    数组型参数和数组的区别
    Oracle数据库建库、建表空间,建用户
    oracle表空间操作详解
    Oracle10g的完全卸载(转载)
    Delphi format的用法
    AnImateWindow用法
    文本文件操作
    TStringList的用法
    Delphi网络函数
  • 原文地址:https://www.cnblogs.com/fswhq/p/UncategorizedSQLException.html
Copyright © 2011-2022 走看看