This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best practice for dividing search results into pages

 
Edmund Castermund
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's info on this in the JspFaq.

And yes, making the database do the work is the right approach.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is DB-dspecific syntax. Using JPA or Hibernate eliminates the dependence on a particular SQL dialect.
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was oblivious to the fact that Informix had such a feature:



Time to do some refactoring.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic