CachedRowSet 是否适用于所有 ResultSet 实现?

发布于 2024-07-24 08:44:54 字数 1818 浏览 1 评论 0原文

我正在尝试使用 CachedRowSet 来分页 AS400JDBCResultSet 包含我的查询结果。

我尝试过使用该

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

方法,但完整的结果集(65 条记录)在第一页中返回(即通过调用 cachedRowSet.next())。 我也尝试过这种

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);

execute() 调用上抛出了以下异常

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)

方法,但是在我在 IBM 和 IBM 上尝试过的 。 Sun JRE。

有任何想法吗? 我的 JDBC 驱动程序是否完全不支持此功能?

更新: MySQL 驱动程序也会发生这种情况 - 所以我一定做错了什么,对吧?

更新 (2): 让它可以工作了关于 Java 5.0 和 6.0 适用于 MySql 的 Driver,但仅适用于我的 AS400JDBCDriver 6.0 - 均使用上面的方法 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2024-07-31 08:44:54

听起来您的驱动程序可能不兼容 JDBC 3.0,这是在 API 中引入行集的时候。 AbstractMethodError 支持这一点。

检查您的驱动程序文档以了解它声称支持哪个 JDBC 版本。

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.

你另情深 2024-07-31 08:44:54

随着 Java 版本的更新,调用驱动程序的方式也发生了变化。 老派有额外的样板,但它仍然适用于 Java 6。

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文