views:

640

answers:

2

I'm trying to implement a database paging solution (forward only required) using a CachedRowSet to page an AS400JDBCResultSet containing the results of my query.

I've tried using the

CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.setMaxRows(10);
cachedRowSet.setPageSize(10);
cachedRowSet.populate(resultSet);

approach, but the full result set (65 records) is returned in the first page (i.e. by calling cachedRowSet.next()). I've also tried the

CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.setPageSize(10);
cachedRowSet.setMaxRows(0);
cachedRowSet.setUsername("username");
cachedRowSet.setPassword("password");
cachedRowSet.setUrl("jdbc:as400://dev;naming=system;libraries=*LIBL;prompt=false;");
cachedRowSet.setCommand(query);
cachedRowSet.execute(connection);

approach, but I get the following exception thrown on the execute() call

Exception in thread "main" java.lang.AbstractMethodError: java/sql/DatabaseMetaData.locatorsUpdateCopy()Z
    at com.sun.rowset.CachedRowSetImpl.initMetaData(CachedRowSetImpl.java:712)
    at com.sun.rowset.CachedRowSetImpl.populate(CachedRowSetImpl.java:617)
    at com.sun.rowset.internal.CachedRowSetReader.readData(CachedRowSetReader.java:190)
    at com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:756)

I've tried on both IBM & Sun JREs.

Any ideas? Is this functionality just plain not supported by my JDBC driver?

Update: Also happens with MySQL driver - so I must be doing something else wrong, right?

Update (2): Have got it to work on Java 5.0 & 6.0 for MySql's Driver, but only on 6.0 for my AS400JDBCDriver - both using method 2 from above. Seems to be quite slow in any case.

A: 

It sounds like your driver may not be JDBC 3.0 compliant, which is when rowsets were introduced to the API. The AbstractMethodError supports this.

Check your driver documentation to see which JDBC version it claims to support.

skaffman
Harry Lime
A: 

The way that the drivers are called have changed with the newer versions of java. The old school had extra boiler plate, but it still works with Java6

    Connection c = null;
    try {
  Class.forName(driverString);
 } catch (ClassNotFoundException e) {
  //TODO
 }
    c = DriverManager.getConnection(url, username, password);
WolfmanDragon
Thanks for the answer, but I've tried using the method of setting driver names from the DriverManager javadocs (setting the jdbc.drivers System Property). It makes no difference - same error for the AS400 driver :(
Harry Lime