This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 60800

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60800

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
Similar Threads
Maintain checked and unchecked in checkbox in pagination in display tag in struts
JSP and JDBC errors
Sorting the fields of a table
Dynamic defining fields in Strtuts-config.
How to show only 10 entries in a jsp-page?