spring jdbcTemplate how to catch exception?

后端 未结 3 1954
暖寄归人
暖寄归人 2020-12-31 03:39

Everything is brilliant until I encounter place where I actually do need to catch exception. When I place

jdbcTemplate.query(something...)

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 04:23

    That's because SQLException, a checked exception, is not thrown by the any of the JdbcTemplate.query(...) methods (javadoc link). Spring translates this to one of the DataAccessException, which is more generic family of runtime exceptions, in order to abstract away any specific underlying database implementation.

提交回复
热议问题