Originally posted by atifwasi:
I need help or routine for jsp about how i retreive 10 rows per page with next and previous page button, just like technical forum.
Unfortunately, you give very little indication at what kind of level you need help -- where are you getting stuck?
I might be stating the obvious: the next and previous link (or button) should invoke your JSP (or
servlet) with enough information to determine which records to retrieve. The most naive way would be to invoke the same JSP with a record range, i.e. href="mypage.jsp?records=20,40". A slightly more sophisticated approach would use an MVC (Model 2) architecture and invoke a controller servlet with a next/previous command, e.g. href="/servlet/controller/mypage.jsp?action=next".
Once you've decided how to set up the control structure, the next problem is how to actually retrieve the desired records. There are basically three alternatives, the one you choose depends on the type of application you're developing.
You can, at the first query, retrieve all results in an ArrayList and bind that directly in the session or store it in a session-scoped JavaBean. This makes retrieving arbitrary parts of the result set very easy but it may eat more memory than you can afford.
If you're using JDBC 2.0, you can make use of the new scrollable ResultSet -- it's got previous(), next(), first() and last() methods. Of course that means you'll have a ResultSet object lying around in your session consuming resources.
Finally, you can re-do your query, preferably formulating it in such a way that only the desired records are returned. For example, if you would be using an Oracle database, you would be able to simply say "SELECT [...] WHERE ROWNUM BETWEEN 20 AND 40".
All the above assumes you're not using Enterprise JavaBeans.
- Peter