String handlersql="select count(*) from d_handler where unitcode=? and handlercode=?";
int handlercount=jdbcTemplate.queryForInt(handlersql,logininfo.getUnitcode(),logininfo.getHandlercode());
表里对应的上面的查询条件是有一条数据的,但是用queryForInt查出来的 handlercount=0,求解决。
logininfo.getUnitcode()
logininfo.getHandlercode()
看下这两个值分别是什么?我觉得是你这两个值传的对应根本查不到数据
[code="java"]打印sql 放分析器执行下 可能你传入的 where字段内容有差异哦[/code]
试试下面的语句:
select count(*) t from d_handler where unitcode=? and handlercode=?
确保你的sql 在sql 分析器中 执行有结果
例如:
select count(*) from d_handler where unitcode=? and handlercode=?
后面where 的部分 返回为false 数据库不存在 你传入的条件的记录
queryForInt方法参数好像是sql+参数数组哦
jdbcTemplate.queryForInt(handlersql,new String[]{logininfo.getUnitcode(),logininfo.getHandlercode()});
参数没有设对
楼主可以试试:int handlercount=jdbcTemplate.queryForInt(handlersql,new Object[] {logininfo.getUnitcode(),logininfo.getHandlercode()});
如果不行 就是logininfo的参数数据类型与数据库字段的数据类型不匹配
JdbcTemplate的QueryForInt()方法有三种重载,
1、jdbcTemplate.queryForInt(sql);
2、jdbcTemplate.queryForInt(sql, Object[] args);
3、jdbcTemplate.queryForInt(sql, Object[] args, int[] types);
后面两个参数分别是对应?的参数值和该参数的类型,请确认jdbcTemplate.queryForInt(handlersql,logininfo.getUnitcode(),logininfo.getHandlercode());
是否调用和传递正确。