Hi I want a solution for the following Iam retriving data from a table and displaying the same in the JSP (using grid). There are nearly 500 regards and Iam dispalying 100 on first retrevial. If I click on next, it will hit Database and retrive next 100 records and so on. The same is applicable when I click on previous button. To know how many records are there, Iam first writing a count query. this is used to dislay on the screen like " 100 of 505 records". Then I will write the query to display the coloumns which get 100 records. In summary Iam hitting DB 2 times ( First to get total count and second to get 100 records). This is hitting the performance. Can't I write one query which counts the total records as well as get the first 100 rows whcih colown values ? Pls let me know how to achieve this ?? Regards B S Reddy
- Posted by: Srin Reddy
- Posted on: January 04 2007 01:39 EST
- Re: Dispalying the Data in the grid by using next and previous by amadeu heredia on January 04 2007 07:07 EST
- Re: Dispalying the Data in the grid by using next and previous by Christopher Stach II on January 04 2007 08:18 EST
You can adapt the ValueListHandler J2EE pattern (http://java.sun.com/blueprints/corej2eepatterns/Patterns/ValueListHandler.html) You make only one query to DB to get the whole list. Then, save the list into the Session and, for the next requests to the list, you query to the list Object on the session, not to the DB. To take the length of the list, list.size(). You can take the 101-200 records iterating over the same list.
Things like SQL_CALC_ROWS and FOUND_ROWS() would help. google.