Hi,
For a long time I was/am convinced that it is good to use prepared statement eventhough you are not going to use them propertly, cause whenever in the future you are going to modify your code to use your connections wisely along with prepared statements it will save you valuble execution time.
I have following enviornment....
Miscrosoft SQL Server 2000 driver for JDBC
Jakarta-Commons DBCP (have prepared stmt pooling on)
Tomcat as the web app.
(I would not like to use Tomcat's internal CPooling cause we may have to migrate to some other app server and then the installation process and everything should have been changed.)
Now to the actuall question.... in a transacation I have 2 to 3 different sets of queries (some SELECTs, some UPDATEs and some INSERTs)
say I have QUERY1 , a SELECT query and QUERY2 an UPDATE query in a transaction T1. Will following code utilize features of PreaparedStatement properly??
String q1 = QUERY1;
String q2 = QUERY2;
PreparedStmt pStmt = null;
pStmt = conn.prepareStatement(q1);
rs = pStmt.executeQuery();
Object obj1 = processRS (rs);
pStmt = conn.prepareStatement(q2);
myint = pStmt.executeUpdate();
pStmt.close();
Do I need to have "pStmt.close()" btw "Object obj1 = processRS (rs);" and "pStmt = conn.prepareStatement(q2);"?
Thanks a lot.