my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Connection Pool & Prepared Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connection Pool & Prepared Statement" Watch "Connection Pool & Prepared Statement" New topic

Connection Pool & Prepared Statement

Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
If a code is using connection pooling will the benefit of using Prepared Statement is valid.

Say, if i take a connection from a pool, prepare a statement using that connection, execute the querry and release the connection to pool. Now for the second time when i take a connection from the pool, i do not get the same connection as the previous one. On this connection will the advantage of prepare statement be still present, even though the previously the statement was prepared using a different connection.

Yes/No, but an explaination will be highly appreciated.

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

When you make a prepared statement in java the SQL statement is compiled parsed at DB end. After compiling and parsing the SQL statement same is placed in shared global area of database.
when a new query is received by database (either by same connection or new connection) it is checked against shared global area.
If it exist in shared global area same is used otherwise compiled-parsed and placed in shared global area of data base.

so connection instances is not actually in picture as shared global area are available to every connection.

To have advantage of PreparedStatement you database should support the Preparedstatment. Now a days Almost every database support it.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
Thanks for the information
I agree. Here's the link:
subject: Connection Pool & Prepared Statement
It's not a secret anymore!