Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scrollable result sets and physical reads...

 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found it, the thread I liked is here
Dave
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks for the advice!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic