• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

design issue...

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic