tags:

views:

302

answers:

2

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

+6  A: 

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.

Thomas Jung
thanks Thomas, my problem is somewhere else then.
combi001
A: 

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

Aito