|
I agree with Richard's strategy *but*
I think it lacks an important feature:
paging.
You may want to check the thread
"Paging large database result sets"
Executive summary:
1. provide a method to get the count of records
that fit the query
2. provide a method to get a pge of
records
So instead of:
public class PayRollBean implements javax.ejb.SessionBean [ use:
public class PayRollBean implements
javax.ejb.SessionBean [
public int getEmployeeSalariesCount(){ DataSource dataSource = (DataSource)cntx.lookup("java:comp/env/jdbc/db"); Connection con = dataSource.getConnection( ); Statement stmt = con.createStatement( ); ResultSet set = stmt.executeQuery("select COUNT(*) from EMPLOYEE"); return
set.getInt(1);
}
public Vector getEmployeeSalaries(int pini, int ptot){ DataSource dataSource = (DataSource)cntx.lookup("java:comp/env/jdbc/db"); Connection con = dataSource.getConnection( ); Statement stmt = con.createStatement( ); ResultSet set = stmt.executeQuery("select LNAME, FNAME, SALARY from EMPLOYEE"); // get a page using JDBC
1.22
/*int nrec = 0;
int tot =
pini+ptot;
Vector result = new Vector(); while( set.next() )
{ if ( nrec++ < pini )
continue; // wasted effort JDBC 1.22
if (
(ptot>0)&&(nrec>tot) ) break;// no more records, thank
you
result.addElement(
makeAnObjectOutOfCurrentRecord() ); }*/ // get a page using JDBC
2.0
absolute(pini);
int nrec = 0; Vector
result = new Vector(); //if ( nrec++ < pini ) continue; // NO wasted effort
using JDBC 2.0
if (
(ptot>0)&&(++nrec>tot) ) break;// no more records, thank
you
result.addElement(
makeAnObjectOutOfCurrentRecord() ); }return result; } ... } The client first asks how many
records fit the query, then asks for pages
depending on the user
actions.
This way we are not collapsing the client memory
with thousands of records
it does not really need.
Regards
Javier
|
- Re: Cached Rowsets-do we need t... Victor Langelo
- XML vs. Serial (was: Cache... Tim Endres
- Re: XML vs. Serial (wa... Victor Langelo
- Re: Cached Rowsets-do we need to use them Neil Thorne
- Re: Cached Rowsets-do we need to use them Victor Langelo
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Neil Thorne
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Javier Borrajo
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
- Re: Cached Rowsets-do we need to use them Richard Monson-Haefel
- Re: Cached Rowsets-do we need to use th... Laird Nelson
- Re: Cached Rowsets-do we need to us... Richard Monson-Haefel
- Re: Cached Rowsets-do we need to use th... Aravind Naidu
- Re: Cached Rowsets-do we need to us... Richard Monson-Haefel
- Re: Cached Rowsets-do we need to use th... Doug Sjoquist
- Re: Cached Rowsets-do we need to use them James Cook
- Re: Cached Rowsets-do we need to use them Louth, William (Exchange)
