qeuryForLong

org.springframework.jdbc.core.JdbcTemplate 使用注意事项

亡梦爱人 提交于 2019-12-17 15:59:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在使用JdbcTemplate.queryForMap(String )的时候发现一个问题: 错误信息如下: org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expected 1, actual 0 通过查询官方API: https://docs.spring.io/spring/docs/2.0.x/javadoc-api/org/springframework/dao/EmptyResultDataAccessException.html Data access exception thrown when a result was expected to have at least one row (or element) but zero rows (or elements) were actually returned. 注意事项: 如果要是有 queryForMap(sql)和qeuryForInt(sql)和qeuryForLong(sql) 要注意当Map 为空的时候会抛出异常。 如果不想抛出这个异常,要么就用queryForList(sql)吧。 来源: oschina