File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes MULTIPLE Query IN a RS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MULTIPLE Query IN a RS" Watch "MULTIPLE Query IN a RS" New topic


avijit majumder

Joined: Sep 01, 2009
Posts: 15
How can I run Multiple Query in A Single ResultSet ?
String st1="select sum(salary) from v_table where id=2 and post!='manager'";
String st2="select sum(salary) from v_table where post!='staff'";
java.sql.Connection con=....
java.sql.Statement st=con.createStatement();
java.sql.ResultSet rs=st.executeQuery(st1); //-----I put one String ...
//dosome thing.
java.sql.ResultSet rs1=st.executeQuery(st2); ///---------I put second string
//dosome thing.

NOTE: I need Only one result Set. and one loop while( but the rs content both two result
Like AddBatch--->
java.sql.Statement stmt=con.createStatement();
stmt.addBatch(insert_query1); //insert_query1="insert intto table1 values....
stmt.addBatch(insert_query2); //insert_query2 ="insert intto table2 values....
int[] inserts = stmt.executeBatch(); // both table insert complet

ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
If you want to use a single result-set then its a better idea to close the first one (off course after result set has been iterated) and then executeQuery on the same instance of result set. See the code below, you will get a better idea

Try this

However, if you want to use a single resultset then you need to modify your query

Ujjwal B Soni <baroda, gujarat, india> <+918866008962>
"Helping hands are better than praying lips......"
I agree. Here's the link:
subject: MULTIPLE Query IN a RS
It's not a secret anymore!