2

Possible Duplicate:
Prepared statement pooling in dbcp

I am building a web application that uses Tomcat's Database connection pooling mechanism for its internal use. I am trying to pool the prepared statements as well so that the application is more efficient in retrieving data.

From what I understand, connections are returned to the pool when the connection, resultset and statements are closed. If appropriate flags are set, abandoned connections are also closed and returned to the pool. Closing a connection means releasing all database cursors and cached statement including prepared statements. So whats the point of prepared statement pooling?

Community
  • 1
  • 1
BegaluruBoy
  • 95
  • 2
  • 7

1 Answers1

8

A generic answer :)

Connection objects are not really closed but only returned to the pool when you call close() and the prepared statement pooling works on per connection basis and they are cached as long as the connection object remains active.

srikanth yaradla
  • 1,225
  • 10
  • 13
  • 5
    The key insight here is that the objects the pool gives you are not the real connections and statements, they're wrappers. When you close them, you return the real things to the pool rather than closing them. – Tom Anderson Aug 09 '12 at 19:33
  • I was expecting this answer everywhere but could not find it. I read about Apache Commons DBCP having a wrapper class called {PoolableConnection} where calling close() just returns the object without closing the connection but I was not sure. Thanks for the info. – BegaluruBoy Aug 10 '12 at 02:44