Posted By:
Stephen_McConnell
Posted On:
Wednesday, September 26, 2007 11:39 PM
Much of the details depend upon what type of application you are writing.... Is it a web ap... and applet, general application . . are you using JDBC or Hibernate or some other method of accessing the DB.... etc etc But an overview of the solution goes like this:
Most SQL dialects have a clause Limiting the number of rows returned from a query.
Postgresql uses a SELECT ..... LIMIT { count }
DB2 uses a FETCH FIRST n ROWS ONLY" in its SELECT statement.
You need to find what is the "Limiting" clause for your SQL dialect.
What one does is keep two key values in memory in the session object or whatever. The first one is the key of the first record in the recordset. The second is the key of the bottom record in the record set.
To page forward you issue a query selecting the next "n" records that are greater than the key at the bottom of the page.... (If the result set returns empty or less than the number you want, you have reached the end of file and you want to disable the NEXT button.)
To page backward you issue a query selecting the "previous" "n" records less than the key at the top of the page. (If your record set is empty, then you have reached the START of the file - and you want to disable the PREVIOUS button)
Once the result set is read in, you replace your top and bottom keys with the first and last records in the resultset.
This is a general idea. Coding it is half the fun. I seem to dimly remember this might have similar to the first question I answered on this forum YEARS and YEARS ago...