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?
Set the query timeout for statements that this JdbcTemplate executes. Default is 0, indicating to use the JDBC driver's default. Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
Spring Example JDBC Database Connection PoolJdbcTemplate requires a DataSource which is javax. sql. DataSource implementation and you can get this directly using spring bean configuration or by using JNDI if you are using the J2EE web server or application server for managing Connection Pool.
The Spring JDBC Template has the following advantages compared with standard JDBC. The Spring JDBC template allows to clean-up the resources automatically, e.g. release the database connections.
Hibernate makes a lot of assumptions and forces you to think and code in a certain way. Using JdbcTemplate is easier because it's just a very thin wrapper around JDBC itself. The price here is that you will write thousands of lines of really boring code. Also, you will find that SQL strings are really hard to maintain.
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.
Yes it does.
And if the connection was obtained from connection pool, it won't actually close the connection, rather will send it back to the pool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With