首页 > 数据库技术 > 详细

JdbcTemplate queryForMap EmptyResultDataAccessException

时间:2014-10-20 16:59:19      阅读:325      评论:0      收藏:0      [点我收藏+]

JdbcTemplate的queryForMap方法报错
queryForMap方法使用不当,就会出错,使用方式如下:
The queryForMap method in JdbcTemplate only expects a single row to be returned, The return value for this method will be a map of column names to column values for the single result row.

queryForMap方法返回的结果集大小必须是1,并且返回的map中,以列的名字作为key,获取的值作为value

利用spring 的getJdbcTemplate().queryForMap如果返回空集,就会报
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 的异常
try{
return getJdbcTemplate().queryForMap("select s.fb,s.pb,s.tu,s.qt,s.fbc,s.pbc,s.tt,s.ft,s.lt from gbc$view_user s where s.ud = ? and ad= ?", new Object[]{ud,ad});
}catch (EmptyResultDataAccessException e) {
return null;
}

解决方案 在queryForMap的地方 try catch 一下 即可。

JdbcTemplate queryForMap EmptyResultDataAccessException

原文:http://www.cnblogs.com/yangy608/p/4037460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!