Server side Prepared Statement usage
Posted by: th_nabe
Date: February 05, 2005 06:18PM

Hello,

I have used prepared statements almost exclusively when invoking JDBC calls (because of the putative performance advantages).

But I've spent some time perusing the code (3.1.6) and this forum and I'm wondering whether I've been using them correctly.

It looks like any PreparedStatement instance (created via connection.prepareStatement("SQL . . .")) is only "re-usable" on the "same" connection instance, and in fact is only re-usable by client code maintaining a reference to the original PreparedStatement instance. Is this correct?

Example:
final String SQL_SELECT = "SELECT * FROM Table WHERE x = ?";
PreparedStatement prep = conn.prepareStatement(SQL_SELECT);
prep.setInt(32);
Resultset results = prep.executeQuery();
////////Process resultset
///////Use again with same references
prep.setInt(33);
results = prep.executeQuery();
////////Process new resultset
My question is, is this the only way to gain the performance benefit from a PreparedStatement?i.e. there is no connection-level or (even-better) DataSource-level "cache" of PreparedStatements?
so that conn.prepareStatement(SQL_SELECT) checks the client-side cache to see if there is a com.mysql.jdbc.PreparedStatement instance already associated with the "key" SQL_SELECT?

Options: ReplyQuote


Subject
Written By
Posted
Server side Prepared Statement usage
February 05, 2005 06:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.