Suppose I need to query a database and the result contains 100K of records. Can someone please show me a code example of how to "page" the result for, say, 1K of records at a time?
If you are using a relational database and the data is ordered then you can do the paging in the SQL statement, on many DBs anyway. Something like:
The fetch statement controls the number of rows returned. Set lastKey to the key of the last record in the previous page. There's probably a better way to do it, but that should work.
So? What does that have to do with anything? The whole concept of paging ties in with the order with which rows are to be returned. You can specify whatever sorting you like with an ORDER BY clause.
There's a JSP FAQ entry on this subject, by the way.
Here's the link to this nice JavaRanch Howto from the JSP FAQ: PaginationOrPaging : How do I limit the number of rows displayed in the browser? Regards, Jan [ November 13, 2007: Message edited by: Jan Cumps ]
I'm probably missing something here, but I can't see a solution that will work with un-ordered data. If the data is not ordered, then can you guarantee that rows will be returned in the same relative position over multiple queries? Or is the data ordered but not keyed?
John [ November 13, 2007: Message edited by: John Simpson ]
Originally posted by John Simpson: I'm probably missing something here, but I can't see a solution that will work with un-ordered data. If the data is not ordered, then can you guarantee that rows will be returned in the same relative position over multiple queries? Or is the data ordered but not keyed?
John
[ November 13, 2007: Message edited by: John Simpson ]
you include an order by clause in your query.
No thanks. We have all the government we need. This tiny ad would like you to leave now: