aspose file tools*
The moose likes JDBC and the fly likes Scrollable result sets and physical reads... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Scrollable result sets and physical reads..." Watch "Scrollable result sets and physical reads..." New topic
Author

Scrollable result sets and physical reads...

SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
If I create a scrollable result set like this....
Statement st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery("Select * from products");
rs.setFectchSize( 50);
Lets say that there are 10,000 rows that match the query criteria, I only want to fetch, say, 50 rows at a time. Clearly, I don't want the first fetch to get all the 10,000 rows because I am storing the result set in the session.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Safrole,
Storing a result set in the session is dangerous because the resultset is tied to your statement, which is tied to your connection. The connection could close at any time. You would be better off storing a copy of the data you need.


[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
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Search this forum for 'ResultSet paging', there have been a few discussions on ways to do this efficiently. The short answer is that there are multiple ways to do it, and no single solution matches all requirements.
There was one really good one where someone brought all the discussions together. I'll have a look for it.
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Found it, the thread I liked is here
Dave
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
Ok, thanks for the advice!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scrollable result sets and physical reads...