File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Paging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Paging" Watch "Paging" New topic



Joined: Oct 25, 2000
Posts: 2
Can we do paging of result retrieved from database (i.e only ten results should be shown on first page another ten on next page and so on). If yes then how ??
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
This is a fairly standard question. There are several possible answers which depend on how much data you have to display, and where it comes from.
If you have a relatively small amount of data, which you can get before you display any pages, you can put it in an array (or an ArrayList, or Vector or other indexable data structure) and put that in the session with some indication of what you have displayed already. Each new page request can then show the next page of the data.
If you don't know how much data you have, or it is "expensive" to get it all at once, you really have to go back to the source for each new page. If your data is stored in a database, then you can generate slightly different SQL for each page to retrieve only the items you are interested in - the exact details depend on how your data is stored, of course.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Paging
It's not a secret anymore!