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 ResultSet question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet question" Watch "ResultSet question" New topic
Author

ResultSet question

Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
hey folks,
the code:
-----------
ResultSet r1=statement.executeQuery(select * a);
ResultSet r2=statement.executeQuery(select * b);
-----------
for some reason r1 is ok, but r2 is empty.
if i make a totally new statement for the second ResultSet, like this:
-----------
ResultSet r1=statement1.executeQuery(select * a);
ResultSet r2=statement2.executeQuery(select * b);
-----------
everything works fine.
i just don't want to open another connection to make a second statement, and i have examples where the first solution works fine. any ideas what is the problem?
thnx


Asher Tarnopolski
SCJP,SCWCD
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
From the api:
A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.

So in your case you should have 2 separate statement objects.
-Pat
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

You can create two statement objects from the same connection object, so you don't necessarily have more connections.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet question