Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do you fetch a limited # of rows

 
Qaiser Chaudhry
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do research on how to fetch a limited number of rows. The problem that's prompting me to do this is that I am working with Tomcat (with Sybase) and when multiple users fetch a page with a list on it, a large number of records are loaded for each user. What I am trying to achieve is fetching only the records that will fit on that page. Can this be achieved by using cursors? Please help.
 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ResultSet has a method setFetchSize() which you can use to specify the number of rows you want to fetch.
hth...
raymond
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method may not be supported by all JDBC drivers. It depends on the database you may be using.
 
Qaiser Chaudhry
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already tried setFetchSize(x), but that means that when you do a select statement, you will the first x number of records that show up in the resultset. How do I get to the next set of x number of records? I would like to be able to get to any point in the the resultset and pick out x number of records.
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to ask yourself if you want to fetch all the records and display some at a time, or fetch some and display them , then fetch the next or previous set if needed.
if you want to fetch all then yes the cursor will achieve this but the other records may never be requested and resources will have been wasted.
if you want to get some only then you'll need to know where you last stopped.
i recently fixed a similar problem, the jsp was sent 20 megs to load at once, hehe, so i had the session hold an int (offset) for the last record he saw, and if he wanted the next or previous 20 i'd setMaxRows(20) and start fetching based on the offset.
theres probably a better way to do it but i couldn't think of it so thats what i did.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic