org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #2 with JdbcTyp
又是coding的一天,老项目,五十多行的sql,map 19个参数 要改造...
sql测试通过,上项目,跑起来。。。
然后 org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #2 with JdbcTyp
你TM倒是告诉我是哪个参数不对啊,第2个,第二个是啥,hashmap是无序的
跟代码,苦哈哈的跟到 DefaultParameterHandler 这个类的 setParameters()方法,找到了对应的参数异常,少了一个。。。
长了个记性,以后不能偷懒。参数里如果写了参数类型,sql可以正常执行,我们也就能看到是哪个参数忘带了。如以下两种写法
where FULLPATH_L2 like #{fullPath,jdbcType=VARCHAR}||'%'
statment 执行是不会中断的,我们可以在mybatis 的log中看到以下参数,null 就说明有参数异常
Parameters: 1(String), 202008(String), 202008(String), null, 1(String), 202008(String), null, 1(String), 202108(String), 202108(String), null, 1(String), 202108(String), null, 1(String), 202108(String), 1(Integer), 10(Integer)
而不过不带jdbcType
where FULLPATH_L2 like #{fullPath}||'%'
statment 执行会异常中断,可能只会给你一个干巴巴的异常,自己悟去。。
org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #2 with JdbcTyp