i am using a stored procedures to retrive the data from the database.I want that data to be displayed in various pages that is if the user clicks "next" hyperlink in the main page another set of data is to be displayed.please give me details with how to implement it with source code.
U can do it in a number of ways.
1). When user comes on the page for the first time, fire the sql to get the count of 'TotalResults'. Then fire another sql to retrieve the results from 1 to 'ResultsPerPage' or the 'TotalResults', whichever is less. Store the current page number in the Bean, and retrive this value on subsequent clicks of 'Next' or 'Previous' links. On each such click, the two sqls will be required to fire. The most important thing is the retrieval of records for a page. Here only those number of records need to be retrieved which are to be displayed on that page. Here, u can use 'rownum' concept. This concept is available with Oracle 8i (I am not aware of availability of it with SQL Server 7/2k).
Also, U can use Custom Tags to display the 'Next-Previous' links.
2) Another way of doing is to retrieve all the records, and keep them all in the cache. Sun has just release the early access version of Rowset Implementation.
The way u implements will, however, depend on the requirement, and the architecture of the application u r developing.
Hope it helps.
<rajneeshgarg at usa dot net>
Guru, I'll add one comment to the suggestion made by Rajneesh. If you know at design time (one rarely does, though) that the number of records retrieved will always be 'reasonable', you can transfer the query results to Java objects and stuff them into an array. That avoids the necessity of firing another query with each page change. This is what Rajneesh was trying to help you avoid when he suggested using the Rowset. But if Rowset is not a viable option for you, give some thought to this other idea.
I agree with Gordon when he says that firing of second sql can be avoided if resultset is not 'large'(?). Use of Collections framework ot retrieve the entire resultset in one go can help u. However, u will need to consider all the facts before deciding the implementation:
1) Firing two sqls on each page requires a database connection on each page. Database connections are the most precious, and most time consuming, resource in the web- based apps.
2) When retrieving data thro RowSet API, u will have to take into consideration that the resultset u had retrieved will remain in the memory, which may again prove to be a big burden on memory.