Jigar S. Shah [I] <[EMAIL PROTECTED]> wrote:
>we would like to give an option to ther user to restrict his search
>results to a particular number and provide a button to go the next
>results as we have in common search engines
>
>I am not sure how this can be done using servlets, I do not want to
>make a new connection to the database each time user clicks "Next
>results", How can i store the resultset from database and get the next
>results.
Get all the data and save it to a local cache file or store it with the
user's session. Then build the first page and return it. When the user wants
to see the second page, use the data from the cache file or from the user's
session to build the second page.
To make things easier, you could write a class that reads a text file and
returns a ResultSet object. I have done such a thing. It's pretty easy. If
you want to have a look at my code, let me know. That way, my database
accessors always read from a ResultSet. Sometimes the data is from the
database, other times it's from the local cache file, but my database
accessing code doesn't know (or care).
The drawback of such a system is that if the user only gets one pageful and
then goes away, you have just wasted a lot of time getting all the rows from
the database and saving them to a cache file. As a tradeoff, you could
always get five (or so) pages-worth of data and save them to the cache file,
and then go back to the database if the user wants more. Or only get one
page-worth the first time and if the user asks for the second page, get the
next 10 (or so) pages-worth.
Erik
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html