|
Can i use the same statement and resultset objects for executing multiple query?
hi,
i just want to know whether, i can use the same statement and resultset objects for execuing multiple query? The scenario is like this
try{
// Get the connection object
//Declare resultset
//declare statement
String queryA="select * from xyz";
String queryB = "select * from abc";
//Executing first query
stmt = conn.createStatement();
rs = stmt.executeQuery(queryA);
*******************
// DO I NEED TO CLOSE THE STATEMENT AND RESULTSET EXPLICITLY BEFORE RE-USING IT?
rs.close();
stmt.close();
*******************
//Executing the second query
***************************
//SINCE I HAVE CLOSED THE STATEMENT, I AM CREATING IT AGAIN
stmt=conn.createStatement();
**************************
stmt = conn.createStatement();
rs = stmt.executeQuery(queryA);
}catch(Exception e){
// some code here
}finally{
//code to close statement, resultset, connection
}
|