File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Connection Pool & Prepared Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connection Pool & Prepared Statement" Watch "Connection Pool & Prepared Statement" New topic
Author

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.

Nischal
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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.

Shailesh


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: http://aspose.com/file-tools
 
subject: Connection Pool & Prepared Statement