This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JSP and the fly likes sectioning a recordset using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "sectioning a recordset using jsp" Watch "sectioning a recordset using jsp" New topic

sectioning a recordset using jsp

Alfonso Harding
Ranch Hand

Joined: Feb 09, 2002
Posts: 35
I have a database with over 1000 entries. I would like to know how can I break up the entries
so I can display a 100 per page as supposed to displaying the whole record set one page? So if a user gets pulls up the database the first page will display 1-100 and if an icon or link is clicked it will go to 101-200 etc. How can I do this using jsp?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

A JSP isn't exactly the best place to do this type of processing. You should consider filtering down your dataset long before it gets sent to the page.
Depending upon which DB you are using, there may be facilities that make it easy to do this closer to the back end. For example PostgreSQL has LIMIT and OFFSET clauses that you can place on a query that make paging through large datasets almost trivial.
If your database lacks such capabilites you can: (a) switch to one that does, (b) pare down the data sent to the JSP in a controller servlet, (c) pare down the data in a bean that abstracts the query, (d) something else that I haven't thought of yet. (In order of my own preference).
Handling this type of complex logic directly on a JSP is the last thing you want to do.

[Asking smart questions] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

P.S. Do search on 'paging' in this and related forums. This has been discussed quite a few times.
I agree. Here's the link:
subject: sectioning a recordset using jsp
jQuery in Action, 3rd edition