aspose file tools*
The moose likes JDBC and the fly likes ResultSet.next() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet.next()" Watch "ResultSet.next()" New topic
Author

ResultSet.next()

Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84
Curious as to whether or not ResultSet.next() goes back to the database for each call to next() or if ResultSet actually grabs all results in one fell swoop:
ResultSet rs = someConnection.executeQuery("SOME SELECT QUERY");
while(rs.next()) {
doSomething();
}
In other words, if at some point the connection that this ResultSet lives on was closed....would I no longer retrieve results...or were all results pulled and dumped into some sort of list in the ResultSet interface (or is this implementation specific).
Thanks,
Cory Wilkerson
Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
Cory,
These sorts of details are actually left up to the driver vendor. You can specify certain hints, for instance you can setFetchSize which tells the driver how many rows you would like it to fetch at a time. As far as closure goes, ResultSets are "owned" by a Statement object, which in turn is "owned" by a Connection object. If the connection object is closed, the statement is closed which means the ResultSet is closed (or at least it should work that way - databases sometimes have their own quirky *features*).
Note I use the term "owned" here to indicate is created by.
If you really want this sort of detail, dig into your driver manual, and/or buy the JDBC 2.0 API reference book from Addison Wesley.
Cheers,
Robert
Originally posted by corywilk:
Curious as to whether or not ResultSet.next() goes back to the database for each call to next() or if ResultSet actually grabs all results in one fell swoop:
ResultSet rs = someConnection.executeQuery("SOME SELECT QUERY");
while(rs.next()) {
doSomething();
}
In other words, if at some point the connection that this ResultSet lives on was closed....would I no longer retrieve results...or were all results pulled and dumped into some sort of list in the ResultSet interface (or is this implementation specific).
Thanks,
Cory Wilkerson


[This message has been edited by Robert Brunner (edited August 14, 2001).]
Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84
As best I can tell, closing the statement and connection, in this case, kills my ResultSet...as a matter of fact...a call to myResulSet.next() throws a npe...so, as best I can tell, the database driver I'm using, which I have no documenation for, seems to be tied to the database when calls to .next() are made. I didn't know if this was something that Sun defined in the spec...or, as you stated, something that is "left up to the dirver vendor".
Thanks Robert,
Cory
Originally posted by Robert Brunner:
Cory,
These sorts of details are actually left up to the driver vendor. You can specify certain hints, for instance you can setFetchSize which tells the driver how many rows you would like it to fetch at a time. As far as closure goes, ResultSets are "owned" by a Statement object, which in turn is "owned" by a Connection object. If the connection object is closed, the statement is closed which means the ResultSet is closed (or at least it should work that way - databases sometimes have their own quirky *features*).
Note I use the term "owned" here to indicate is created by.
If you really want this sort of detail, dig into your driver manual, and/or buy the JDBC 2.0 API reference book from Addison Wesley.
Cheers,
Robert

[This message has been edited by Robert Brunner (edited August 14, 2001).]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet.next()