读书人

getJdbcTemplate().queryForMap 回到空

发布时间: 2012-08-21 13:00:22 作者: rapoo

getJdbcTemplate().queryForMap 返回空集
利用spring 的getJdbcTemplate().queryForMap如果返回空集,就会报
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 的异常,解决办法就是捕捉这个异常然后返回null即可。

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;}
刚好解决了我的问题,就是这样

读书人网 >其他数据库

热点推荐