Two Laptop Bag
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "ResultSet question" Watch "ResultSet question" New topic

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?

Asher Tarnopolski
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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32804

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: ResultSet question
It's not a secret anymore!