executeQueryForObject returned too many results

depress
  • 554

有一个SQL:

select coalesce(count(1),0) from table where searchDt=#searchDt#

ibatis Dao层是这么写的:

public Integer findCount(String searchDt) throws SQLException {
    return (Integer)this.get().queryForObject("xxxxx",searchDt);
}

现在提示错误:

java.sql.SQLException: Error: executeQueryForObject returned too many results.
    at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:108)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:83)
    at com.boco.monitor.dao.xxxxDao.findCount(xxxxDao.java:112)
    at com.boco.monitor.service.xxxxService.xxxxAnalysis(xxxxService.java:882)
    at com.boco.monitor.task.Task.run(Task.java:35)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

奇了怪了,这SQL打死也不能查出多条结果啊?

回复
阅读 5.7k
2 个回答
✓ 已被采纳

确认一下传入的参数searchDt名字和值有没有问题

  • 列表项目

提示已经很清楚了。queryForObject只需要1条记录,但实际返回了多条记录。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏