3
votes

Example code in "http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html" explicitly closes a connection after it is used.

However according to my understanding, should not it be the connection pool's responsibility to manage active and idle connections?

Why would not I want a connection to be re-used by another transaction?

2

2 Answers

5
votes

You must close the connection so that you can release it back to the pool. The "Connection" you get from the pool does not, per se, represent the actual, physical connection to the DB. Rather it's a wrapper. So, closing the connection informs the pool that it is free for use by other clients of the pool.

2
votes

You need to call Connection.close() to return the connection to the pool, it doesnt actually close the underlying connection.