• 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

Is any problem with this code?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Statement sql = con.createStatement();
ResultSet rs1 = sql.executeQuery(sql1);
ResultSet rs2 = sql.executeQuery(sql2);
String Value1 = rs1.getString(1);
String Value2 = rs2.getString(1);
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jayii Young:
Statement sql = con.createStatement();
ResultSet rs1 = sql.executeQuery(sql1);
ResultSet rs2 = sql.executeQuery(sql2);
String Value1 = rs1.getString(1);
String Value2 = rs2.getString(1);


Yes, that won't work correctly. A Statement can only be used to read one ResultSet at a time. As soon as you execute the second query, the first ResultSet is automatically closed.
If you need to read from more than one ResultSet at a time, then you must use different Statements.
 
Jayii Young
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Blake!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic