Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Pool & Prepared Statement

 
Nischal Topno
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nischal Topno
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the information
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic