Meaningless Drivel is fun!
The moose likes Servlets and the fly likes limit result set displayed per page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "limit result set displayed per page" Watch "limit result set displayed per page" New topic

limit result set displayed per page

Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Sorry if this question is posted elsewhere. I searched and couldn't find it. I am new to Java and am trying to develop my first database driven site using MySQL and JSP.
My problem is deciding on how to go about limiting the result set for a query. If the rs is less than 10 that is ok for my page, but if it's much more what I want to be able to do is display the initial 10 and then at the bottom of the page have numbered links like this:
2 3 4 ->
The idea is it would only ever display 3 numbers at the bottom, and then an arrow pointing either way depending upon how far into the rs you are. eg. if you were at the 45th result set that would have you on the 4th page. At the bottom the numbers would like this:
<- 3 4 5 ->
(and the number 4 would be bolded or something to indicate that is the current page.)
Hopefully I made this clear what I am trying to do. I'm not looking for the code to do this, just the logic behind it. I am very new to Java and am afraid I will approach this problem in away that is to expensive, cause my first thought was to make multiple SQL queries. I am also wondering if the rs should be loaded into an array and then possibly into the session. If I'm way off here please let me know!
dotJ Software

Joined: Sep 20, 2001
Posts: 3
If you are looking to write the algorithm yourself, look at the paging code for jive's message board library. You can download the library and source code at
If you are looking for a pre-written, commercial solution, then take a peek at our grid tag at
Hope this helps ...
I agree. Here's the link:
subject: limit result set displayed per page
It's not a secret anymore!