wood burning stoves 2.0*
The moose likes JDBC and the fly likes best practice for dividing search results into pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "best practice for dividing search results into pages" Watch "best practice for dividing search results into pages" New topic
Author

best practice for dividing search results into pages

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
Hi,
I have an app that goes into a db via jdbc to grab a list of objects and then a servlet presents them in the form of a table.

The app shows the search results in pages....the first 25 results, then click next, 26-50 and so on. Currently, every time the user clicks the link for the next page, a new search is generated returning the entire result set. I realize this is a terrible way to do it. My current plan is to send a page num to the function that calls the sql statement and adjust it to get the results I want...but I was wondering, since this is a ubiquitous scenario, what is the best practice for this?


Also, currently the app gets a list of objects and pulls all the data for those objects whether they are used or not. In terms of scalable db searching code, what is the best practice for this? any good books re: java -> db you can recommend?
bp
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
ok,
answering my own question here. Came across this tutorial:
http://theopentutorials.com/examples/java-ee/jsp/pagination-in-servlet-and-jsp/

This will make it pretty easy to chunk up the search results:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

There's info on this in the JspFaq.

And yes, making the database do the work is the right approach.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Edmund Castermund wrote:ok,
answering my own question here. Came across this tutorial:
http://theopentutorials.com/examples/java-ee/jsp/pagination-in-servlet-and-jsp/

This will make it pretty easy to chunk up the search results:



limit is db dependant, This is mysql isn't it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Yes, it is DB-dspecific syntax. Using JPA or Hibernate eliminates the dependence on a particular SQL dialect.
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 150

I was oblivious to the fact that Informix had such a feature:



Time to do some refactoring.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best practice for dividing search results into pages
 
Similar Threads
Struts advice for a newbie..
Best strategy to send search parameters to pagination method
Looking for pagination patterns or best practices
Multiple sessions paging result sets...
Paging search results and multiple browser windows