简体   繁体   中英

Does CachedRowSet work with all ResultSet implementations?

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 (ie 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.

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.

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 Java 6.

Connection c = null;
try {
        Class.forName(driverString);
    } catch (ClassNotFoundException e) {
        //TODO
    }
c = DriverManager.getConnection(url, username, password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM