Does Spring's JdbcTemplate close the connection if an exception is thrown?

前端 未结 2 987
温柔的废话
温柔的废话 2021-01-04 08:39

When Spring catches an SQLException, does it close the prepared statement, result set, and/or connection before throwing it\'s own DataAccessException (runtime) exception?

相关标签:
2条回答
  • 2021-01-04 09:08

    Yes.

    That's the whole point of JdbcTemplate - it handles all kinds of boilerplate actions including release of all resources. See 12. Data access with JDBC.

    0 讨论(0)
  • 2021-01-04 09:31

    I think your developer should take a look at springs transaction managemant capabilities. You can use AOP to advice logging, rollback behavior and even retry or other exception handling actions to react completly declarative.

    0 讨论(0)
提交回复
热议问题