日期:2014-05-16  浏览次数:20957 次

EmptyResultDataAccessException异常
使用spring的JdbcTemplate.queryForObject(String sql,RowMapper row)方法时,其他情况没什么问题,但是当数据库记录为空时,会抛出EmptyResultDataAccessException异常,原来以为spring把这些异常都封装好了,在网络上搜索答案,原来这个问题遇到的人还不少,但没有好的解决办法,只能catch异常,返回null或其他。

官网社区有帖子建议:

Use the query method instead of queryForObject. It would be better to post questions like this on the Data Access forum.