zoukankan      html  css  js  c++  java
  • MyBatis的参数,不能传入null

    今天在调试的过程中发现一个bug,把传入的参数写到查询分析器中执行没有问题,但是在程序中执行就报错:org.springframework.jdbc.UncategorizedSQLException : Error setting null parameter.  Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: Java.sql.SQLException:无效的列类型
    
     
    
    网上找了很久,才找到了错误原因:myBatis的参数,不能传入null(但是在查询分析器中参数为null是允许的),如果传入了null,SQL在类型匹配时找不到匹配的类型,就会报上面的错。
    
     
    
    解决办法:
    
    1、将null替换成“”字符串;
    
    2、在参数后面添加jdbcType=VARCHAR,
    
    例如:把 insert into user(id,name) values(#{id},#{name}) 
         修改成:insert into user(id,name) values(#{id,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR}) 
    就可以解决这个问题了。
  • 相关阅读:
    C#中Post和Get提交
    C#实现动态页面静态化
    瀑布流的实现
    jQuery常用方法验证
    eclipse配置PHP开发环境
    数据结构学习
    机器学习实战
    Leetcode_StringToInteger
    网络学习
    leetcode_前期心得
  • 原文地址:https://www.cnblogs.com/peter-peng/p/6346929.html
Copyright © 2011-2022 走看看