File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes pagination .....  better approach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "pagination .....  better approach " Watch "pagination .....  better approach " New topic
Author

pagination ..... better approach

Naveen Mishra
Ranch Hand

Joined: Nov 20, 2005
Posts: 75
hi..
I'm in delima what could be a better approach for pagination in a web - based application : it is get data into the memory for onceonly and try manage the things here only ( don't know if it can be done in general ways but if done ... IT INVOLVS MEMORY OCCUPIED , it can go serious if records are in huge number like google search results )

OR

Fetch some n number of records each time and display them ( IT INVOLVS LOTs of CALLS TO DB )

...
which way to go and why ?


Thanks .
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Funny you should mention Google: their policy is to never display more than 1,000 links for a query. Sure, they tell you that there were 2,870,000 hits but they won't show you more than the first 1,000. You might consider copying that idea. Then you just have to read the first 1,000 rows into memory, and your concerns about many calls to the database go away.

Of course this assumes you show the records that are the most important to the user first, like Google does. But you are already doing that, aren't you? You wouldn't make the user click through 20,000 pages in a web application, right?
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Paul Clapham:
Funny you should mention Google:


Google also doesn't use a relational database for their search engine.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by stu derby:
Google also doesn't use a relational database for their search engine.
Perhaps not. But if they had to be prepared to materialize all 2-million pages that matched my search, they would have the same problem as Naveen does. The point is that showing data one page at a time and having millions of rows of that data are features that should not coexist in the same design.
Naveen Mishra
Ranch Hand

Joined: Nov 20, 2005
Posts: 75
Hi. Thanks Paul and Stu for your precious comments on the issue .
I think , I could procceed with Paul's hybrid approach of fetching some good number of records in the memory and play arround with it until user goes beyond those records .It reduces both calls to DB and need of memory to keep huge amount of data.

Thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: pagination ..... better approach