File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to paging database results in different html pages 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 » Servlets
Bookmark "how to paging database results in different html pages" Watch "how to paging database results in different html pages" New topic

how to paging database results in different html pages

juan ramon

Joined: Jan 21, 2002
Posts: 2
Someone can give me some examples code of how to add to my database result page the option of paging the results, I mean to put the next, previous navigation options.
My database is a postgres.
Rick Salsa
Ranch Hand

Joined: Jul 17, 2001
Posts: 173
Hi juan,
Take a look at sun's site.
[ January 21, 2002: Message edited by: rick salsa ]
shai koren
Ranch Hand

Joined: Nov 04, 2001
Posts: 48
If you dont use EJBs you could also add the data from the DB to a list of custome objects and store it in the session. then the links on the page will include params that will indicate the current index and weather it's "next" or "back" which according to you will either add or take the number_per_page (your variable in the servlet/jsp) to/from the index. you just need to watch yourself with the rules for "back" and "next" so that you dont actualy try to get items from the list with wrong index (like -n or more then the list actually has).
Of course if you work with ejbs forget about this one.

Shai koren<br />SCJP2 <br />SCEA (well yea only part 1 so far)
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I disagree with putting search results on the session, but I disagree with putting anything on the session, in general
The best answer to your question is "it depends on the context".
This topic turns up very often and there is some very good material available in this and other forums and I'm not going to try to reproduce it here (I'm bound to get it wrong).
If you search the Servlet, JSP and JDBC forums you will find some excellent discussions.
wood burning stoves
subject: how to paging database results in different html pages
Similar Threads
Pager-tag can't paing if I don't place code in jsp?!
Paging in Struts
JSTL vs DOM generated HTML Table
PreparedStatement - Performance