File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Is any problem with this code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is any problem with this code?" Watch "Is any problem with this code?" New topic
Author

Is any problem with this code?

Jayii Young
Greenhorn

Joined: Dec 11, 2000
Posts: 5
Statement sql = con.createStatement();
ResultSet rs1 = sql.executeQuery(sql1);
ResultSet rs2 = sql.executeQuery(sql2);
String Value1 = rs1.getString(1);
String Value2 = rs2.getString(1);
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
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.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Jayii Young
Greenhorn

Joined: Dec 11, 2000
Posts: 5
Thanks Blake!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is any problem with this code?
 
Similar Threads
Newbie question... :(
Problem in viewing records ?
strange checkbox problem
java Date problem
comparing two ResultSet