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.
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