JdbcTemplate queryForMap EmptyResultDataAccessException
2014-10-20 16:16
537 查看
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 一下 即可。
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的queryForObject抛出EmptyResultDataAccessException异常问题
- 在使用Spring中jdbcTemplate的QueryForObject()方法时异常:EmptyResultDataAccessException
- spring queryForObject 错误org.springframework.dao.EmptyResultDataAccessException: Incorrect result siz
- The method queryForMap(String, Object...) from the type JdbcTemplate refers to the missing type DataAccessException
- Spring jdbcTemplate查不到数据时抛出EmptyResultDataAccessException
- Spring jdbcTemplate查不到数据时抛出EmptyResultDataAccessException
- JdbcTemplate中queryForObject的EmptyResultDataAccessException问题
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1,actual 0 1
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- Spring EmptyResultDataAccessException异常的源码分析和解决方法
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1,actual 0 1
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- 解决 org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected
- EmptyResultDataAccessException
- org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
- org.springframework.dao.EmptyResultDataAccessException
- org.springframework.dao.EmptyResultDataAccessException