Does Spring's JdbcTemplate close the connection after query timeout?
database, java, jdbc, jdbctemplate, spring
Solution
In short yes it does close the connection. The long answer it depends.
When you don't have a Spring managed transaction then yes the `JdbcTemplate` will call the `close()` method on the `Connection`. However if there was already a connection available due to Springs transaction management closing the connection will be handled by Springs transaction support, which in turn also will call `close()` on the `Connection`.
The only difference is when the connection is closed but `close()` will be called.
If the connection will be actually closed depends on which `DataSource` is used, in general when using a connection pool the connection will be returned to the pool instead of actually closing the connection.
Problem
I have set query timeout (getJdbcTemplate().setQueryTimeout(5)) in method with insert statement. What will happen after query timeout, does jdbc template close my connection?