SQL [select count(*) from user where 1=1]; Parameter index out of range (1 > number of parameters, w

这篇博客讨论了在多条件查询时,UserDaoImpl的findTotalCount方法中出现的错误。问题在于尝试直接使用StringBuilder对象作为查询参数,而正确的做法是将其转换为String类型后再传递。修复此错误的方法是将sb.toString()转换为Integer类,从而确保数据库查询的正确执行。

实训-错误记录_

1.报错界面:

在这里插入图片描述

2.原程序

UserDaoImpl–findTotalCount方法
背景:页面多条件查询,需要获取数据库满足条件的数据条数。
在这里插入图片描述

3.原因:第四步,注意。

(下面的是错的,要将StringBuilder 类型的 sb 转为String 型之后再传参!!)

//正确代码
return template.queryForObject(sb.toString(),Integer.class,params.toArray());

在这里插入图片描述

[busicen-nev-dc-service,http-nio-8080-exec-1] org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolved [org.mybatis.spring.MyBatisSystemException: <EOL>### Error querying database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='info.oemId', 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 #1 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 #1 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 (1 > number of parameters, which is 0).<EOL>### The error may exist in URL [jar:file:/app/BOOT-INF/lib/busicen-nev-dc-1.0.5-SNAPSHOT.jar!/mybatis/mapper/VenBuBcBalanceApplyMapper.xml]<EOL>### The error may involve defaultParameterMap<EOL>### The error occurred while setting parameters<EOL>### SQL: SELECT COUNT(*) AS total FROM T_OMS_VEN_BU_BC_BALANCE_APPLY A<EOL>### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='info.oemId', 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 #1 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 #1 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 (1 > number of parameters, which is 0).]
最新发布
11-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT__shan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值