• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fetching records page/page

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Suppose a query fetches some 20000 records from DB & the client displays the results just 10 records per page, How big is the resultset. In ASP we have a provision for fetching the results page by page to reduce the overhead on the server. Do we have anything in JDBC to send results page/page
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by suresh rg:
Hi
Suppose a query fetches some 20000 records from DB & the client displays the results just 10 records per page, How big is the resultset. In ASP we have a provision for fetching the results page by page to reduce the overhead on the server. Do we have anything in JDBC to send results page/page


Hi,
The Statement class contains a method named setFetchSize(int) to specify how much rows should be fetched from server at a time. Issuing such a command won't force the driver to comply; its up to the driver implementation. From what I have observed (SQL Server drivers), if the Statement is created as ResultSet.TYPE_SCROLL_SENSITIVE or TYPE_SCROLL_INSENSITIVE (ie. if Statement makes use of cursors), the hint provided my user on fetchSize is accepted by the driver; otherwise the parameter is just ignored.
regards Jacob
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
Can anyone post some very simple code???
 
suresh guru
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks man.
I am also finding what to do when we need to go for next batch? that is, setFetchSize will help to get first batch of results. But how to go further when user wants to get next batch of results where we should not include previous results. Please tell me if you come across with a solution.
 
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
be a little more clear with your requirements. Are you looking for pagination code? Or do you want to keep the cursor open?
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a word of warning about scrollable resultsets: Besides tying up valuable database resources longer than needed, they are cached as you iterate through them. A common misconception is that when you start iterating in reverse that the previous rows are refetched from the database. What really happens is that as you iterate forwards through the resultset, they will get stored in memory. Depending on the number of columns and the size of each column, 20 000 rows could eat a lot of memory.
My answer to this question is typically, when was the last time you scrolled through 20 000 results? I don't think I've ever made it past 100th entry ( or the 10th page ) on any search engine/pagination web page never mind the 2 000th page!!
Jamie
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some ideas from theserverside.com.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic