【问题标题】:hsqldb 2.3.2 jdbc driver does not support ResultSet.first()?hsqldb 2.3.2 jdbc驱动不支持ResultSet.first()?
【发布时间】:2015-05-13 22:47:09
【问题描述】:

我正在使用 JDK 8 玩 HSQLDB+JDBC 驱动程序。 使用 rs.next() 循环结果可以正常工作,但是,使用 rs.first() 不起作用:不支持功能?!是设计使然还是错误?

我打算用Spring jdbc模板访问hsqldb,担心以后遇到这样的问题会卡住。

    String jdbcUrl = "jdbc:hsqldb:hsql://localhost:9999/configdb";
    try(Connection con = DriverManager.getConnection(jdbcUrl, "SA", "");
        PreparedStatement stmt = con.prepareStatement(
                                "SELECT * FROM contacts");
        ) {

        ResultSet rs = stmt.executeQuery();
        // rs.first() does not work !
        while(rs.next()){
            //do sth here
        }
    } catch (SQLException e) {
        throw new RuntimeException("test jdbc connection failed", e);
    }

【问题讨论】:

  • “rs.first() 不起作用”是什么意思?您是否遇到任何编译/运行时错误?
  • 我得到 sql 异常,说运行时不支持该功能。
  • @Reimeus 默认结果集是只向前的,JDBC 规范说只向前不应该支持first() 和其他滚动方法。不确定它与成为“玩具数据库”有什么关系;这是关于遵循规范。
  • @MarkRotteveel 完全同意!!!

标签: java jdbc hsqldb


【解决方案1】:

尝试让您的 ResultSet 可滚动:

 PreparedStatement stmt= conn.prepareStatement("SELECT * FROM contacts",
   ResultSet.TYPE_SCROLL_SENSITIVE,
   ResultSet.CONCUR_UPDATABLE);

我认为这应该可行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-16
    • 2012-11-26
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 2013-09-06
    • 2021-08-29
    • 2011-03-15
    相关资源
    最近更新 更多