Hi,

I frequently use PreparedStatements, but I am a bit unsure how to properly 
"reuse" them.

I create a statement

String sql = "select * from users where score>?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, n);
ResultSet rs = ps.executeQuery();
// do stuff
rs.close();
ps.close();
con.close();

Now lets say that I want to later reuse that prepared statement, which is 
more accurate:

1) do I need to keep a reference to the actual PreparedStatment object (in 
this case "ps").  If this is the case, do I not close the prepared 
statement?
2) can I "reuse" the preapred statment by just sending the same sql String 
when creating a PresparedStatement from a connection. 

In other words, does the programmer need to keep around references of 
prepared statement objects, or does the database (in this case H2) keep a 
cache based on the parametrized sql String that is sent to the connection.  

Thanks for any help.
-Adam


-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to