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

在使用JdbcTemplate.queryForMap(String )的時候發現一個問題:html

錯誤信息以下:

org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expected 1, actual 0java

經過查詢官方API:

https://docs.spring.io/spring/docs/2.0.x/javadoc-api/org/springframework/dao/EmptyResultDataAccessException.htmlspring

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.sql

注意事項:

若是要是有queryForMap(sql)和qeuryForInt(sql)和qeuryForLong(sql) 要注意當Map 爲空的時候會拋出異常。api

若是不想拋出這個異常,要麼就用queryForList(sql)吧。spa

相關文章
相關標籤/搜索