开发者

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.


What I did, was to extend the JdbcTemplate and override the execute method to use the connection pool (a particular case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜