Results 1 to 3 of 3
- 07-18-2008, 06:15 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
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
}
- 07-18-2008, 08:22 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
No, you don't need to close it (you probably should close the rs though, wrapping it in a separate try/catch block just for all eventuallities).
- 07-18-2008, 01:13 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
SQL Query resultset into Excel Sheet
By chandpuri in forum JDBCReplies: 8Last Post: 01-24-2011, 06:53 PM -
Error When Executing Query
By radz in forum New To JavaReplies: 5Last Post: 06-26-2008, 03:37 AM -
Can I store multiple objects in an array
By lareauk in forum New To JavaReplies: 9Last Post: 05-29-2008, 03:57 AM -
Can I use vectors to store multiple types of objects
By Nathand in forum Advanced JavaReplies: 6Last Post: 04-28-2008, 07:55 AM -
Query with 1 record vs. multiple records
By anderma8 in forum JDBCReplies: 5Last Post: 07-09-2007, 11:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks