IDEA_MyBatis_SQLException:Parameter index out of range坑

2023-05-26,,

报错信息:超出数据库数据表设定的规定长度了

nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='apply_id', mode=IN, javaType=class java.lang.Object, jdbcType=BIGINT, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType BIGINT . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType BIGINT . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1

 

网上说的解决方案大概如下:

这是占位符的数量 跟 设置的参数数量不相等造成的,检查一下你写的sql和传递的参数吧。

特定写like语句所发生的情况:

若是写like语句的时候 ,所用引起的;

在mybatis里面写就是应该是 like  '%${name} %' 而不是 '%#{name} %'

注:${name} 是不带单引号的,而#{name} 是带单引号的

***如果是还不是:可能是注释的原因   --这就是我的坑,主要是IDEA还显示好使,不报错,坑爹呀!长记性了!

因为注释加的位置不对!!

IDEA_MyBatis_SQLException:Parameter index out of range坑的相关教程结束。

《IDEA_MyBatis_SQLException:Parameter index out of range坑.doc》

下载本文的Word格式文档,以方便收藏与打印。