wood burning stoves 2.0*
The moose likes JDBC and the fly likes fetching records page/page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "fetching records page/page" Watch "fetching records page/page" New topic
Author

fetching records page/page

suresh guru
Ranch Hand

Joined: Sep 07, 2002
Posts: 38
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
Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
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

Joined: Sep 07, 2002
Posts: 38
Thanks
Can anyone post some very simple code???
suresh guru
Ranch Hand

Joined: Sep 07, 2002
Posts: 38
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.
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
be a little more clear with your requirements. Are you looking for pagination code? Or do you want to keep the cursor open?
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jul 09, 2001
Posts: 1879

Here are some ideas from theserverside.com.
 
jQuery in Action, 2nd edition
 
subject: fetching records page/page
 
Similar Threads
displaying large number of records in a Jsp page
pagination strategy using caching & ajax
OSCache tag library
Fetching Rows From ResultSets (JDBC).
how to show the request and result in same page