File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes design issue... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "design issue..." Watch "design issue..." New topic
Author

design issue...

mustang india
Ranch Hand

Joined: Feb 05, 2002
Posts: 60
Hey,
I have a search page where the user can provide search criteria. If the result is too large say 10,000 records, I wish to display only 20 records per page. When the usr clicks the next button, he gets the next 20.
My question is is it better to connect to DB and retrive values every time user clicks next or is it better to have all the values stored in ur servlet at one time ? In later case, if 10 users are asking for the data, there is 100,000 records memory is used in the server.
PL advice.
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Hit the datbase each time. This is by far the most common method. One thing you can do is store a reference to the id of the items so that you don't to redo the search, just look up the item requested. Even better (and this is the slickest way I've figured out) is this method.
1) Search for the items and return the first 10 you wish to view.
2) When you do the search for the ten to display, figure out and also return the previous and next ten and store them in the search result object you are using.
3) Now, when you get the next or prev 10 you repeat step two.
This way you always know what the next/prev ten are and can even make your prev/next links "smart" because when you display a set of ten item you know whether or not to show a prev/next link. This also works well if you want to 'step' through the detail pages with a prev/next except you only keep a single reference instead of the prev/next ten. Hope this helps.
Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: design issue...
 
Similar Threads
Displaying records
Hibernate pagination performance problem
Searching in DataTable
Paging
Adding new values in Session