Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Performance question for retrieving data for pagination

Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I got a general question about pagination. I implemented an interface to retrieve some data from the db and to display them as 20 per page.

This could be done by

Either by retrieving all the data and store them in a data structure like ArrayList for example

Or retrieving them from the database as 20 per time.

My question is which way is better.

Obviously, the former way is better if the retrieved data is heaps to store in ArrayList as the size of ArrayList is hugh which takes up memory.
However, the second way, open too many connections because each clicking on the pagination will be one retrieve to the database also. Is it this overhead?

Can someone please advise?

Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the past I have coded this as a compromise between the 2 extremes. I brought back a buffer of the data. Say 10 pages, and if then i would refresh the buffer if the user went past 10. Which method is the most effective depends on query speed, memory constraints and how much data your user pages through.
straws are for suckers. tiny ads are for attractive people.
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic