Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ResultSet question

 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Sheriff
Posts: 35976
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create two statement objects from the same connection object, so you don't necessarily have more connections.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!