aspose file tools*
The moose likes JSP and the fly likes Record Navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Record Navigation" Watch "Record Navigation" New topic
Author

Record Navigation

manish basotia
Ranch Hand

Joined: Jan 12, 2004
Posts: 47
You r fetch ing some records from the data base usually there will be around 100 records its collected ? its going to disply that records ?
It can display all the records in a single page

I need only 20 recors to disply in the page and the remaining in next pages ?

What ur going to do to display that logic ?

I know that thru JDBC we can navigate, but i want to know is there any other possibility.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
The most efficient way to do this is, if you only want one page of data (e.g. 20 records) then only select one page of data from the database.

In order for this to work you need to:
  • limit the number of rows, returned by your DB query, to the page size (*)
  • retrieve the results in a consistent order, ideally by unique key
  • note the unique keys of the first and last records in the page


  • If you want the next page you select rows where your unique key is greater than that of the last record on current page. Guess what you do if you want the previous page!

    (*) This may not be possible on all RDBMS but MS SQL Server has the "TOP n" option; Sybase has SET ROWCOUNT n; and Oracle has the rownum pseudo-column (e.g. WHERE rownum <= n). These are not without their issues, however. Strangely, Mickeysoft has the best implementation here.

    The advantage of this approach becomes particularly apparent when you have, say, 50,000 rows on the database and your page size is 100. You really don't want to pull 50,000 matching rows out of the database and into Java (memory) just to take the top 100 to display in your web page or app GUI and then discard the lot.

    I've seen this kind of implementation (the inefficient one) numerous times on Enterprise systems. It's quite often a major contributing factor to poor user perception of system performance (e.g. their searches seem to take forever).

    Unfortunately I don't have an example implementation I can show you.

    Jules
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    manish basotia,

    JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

    I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

    thanks,
    bear
    JSP Forum Bartender


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Record Navigation