Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Himai Minh

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
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.
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic