• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MULTIPLE Query IN a RS

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I run Multiple Query in A Single ResultSet ?
Example---
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 ...
while(rs.next()){
//dosome thing.
}
java.sql.ResultSet rs1=st.executeQuery(st2); ///---------I put second string
while(rs1.next()){
//dosome thing.
}

NOTE: I need Only one result Set. and one loop while(rs.next() 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


 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

reply
    Bookmark Topic Watch Topic
  • New Topic