简体   繁体   中英

using Spring JdbcTemplate

if i create a new instance of JdbcTemplate like so;

JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

by passing the datasource as a param (the datasource retrieves a connection from server connection pool) am i required to close the connection when im finished with it?

In other words, if i have a pool of connections will the previous code cause my application to create a new connection each time a request executes the code

No. That's the whole deal. Use the JdbcTemplate and it will manage the ressources (Connection, PreparedStatement, ResultSet). It is an implementation of the template method design pattern .

Javadoc :

It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results.

我所做的是扩展JdbcTemplate并重写exe​​cute方法以使用连接池(特殊情况)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM