MyBatis修改数据,超出了预期的范围:org.apache.ibatis.exceptions.### Error updating database. Cause:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='notice_id', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #3 with JdbcType null . 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 #3 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
### The error may exist in NoteMapper2.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: update sys_notice set             notice_title=? --             notice_title=?,         where notice_id=?;
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='notice_id', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #3 with JdbcType null . 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 #3 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2)...........................
Process finished with exit code -1

MyBatis的修改数据库的时候突然爆红了;

大意是参数索引超出了预期的范围。我当时寻思着我难道是id?但是我的id是20,数据有几十条不可能啊;但其实并不一定是id超出范围。

出现这个问题的时候,首先看你的id是不是超出范围了;如果没有:可能是因为在SQL语句中声明了3个参数,但只提供了2个参数值。

错误消息中提到了Parameter index out of range (3 > number of parameters, which is 2),这意味着参数索引超出了预期的范围。可能是因为在SQL语句中声明了3个参数,但只提供了2个参数值。

误消息中还提到了Error setting non null for parameter #3 with JdbcType null,这意味着第三个参数的非空值无法设置,并且JdbcType为null。这可能是因为没有正确配置第三个参数的JdbcType。

确实我这里是声明了3个参数;但是我用注释注释掉了一个参数;【很显然这并没有什么用】

那么把注释的这一段删掉就好了;

总结:
当出现提示超出范围值的时候;

  1. 检查调用update方法时提供的参数值的数量和顺序是否与SQL语句中声明的参数匹配。确保参数的数量和顺序正确。

  2. 检查MyBatis配置文件或注解中是否正确配置了参数的JdbcType。根据你的数据库和参数类型,可能需要手动指定JdbcType。

  3. 如果你像我一样在SQL语句中使用快捷键注释的话;将注释掉的语句删掉,确保是一条完整的正确的SQL语句。

请检查你的代码,特别是SQL语句和参数传递部分,确保它们正确匹配和配置。

  • 24
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值