Java HSQLDB 连接问题

Java HSQLDB connection issue

我一直在制作一个程序,该程序使用 HSQL 连接到我创建的数据库。出于某种原因,我的 class 中的某些方法可以调用数据库并执行命令,而其他部分则不能。我不断收到此错误,

java.sql.SQLFeatureNotSupportedException: 不支持的功能

这是方法,

public List<CustomerInfo> DBgetInfo(String Customer)
        throws ClassNotFoundException, SQLException {

    Class.forName("org.hsqldb.jdbcDriver");
    Connection con = DriverManager.getConnection(urlConnection, userId,
            password);
    Statement stmt= con.createStatement();



    String query = "SELECT * FROM PUBLIC.CUSTOMER";
    ResultSet rs = stmt.executeQuery(query);


    rs.first(); //The error happens on this line


    rs.close();
    stmt.close();
    con.close();

}

我多次使用 运行 调试器,但此方法在 rs.first 行有错误。我已经尝试重新制作数据库,重新导入所有文件,检查以确保命令正确,等等......奇怪的是,在这篇文章的前面 class 我有一个与此非常相似的方法,但是它没有问题。实在想不通是什么问题

根据 documentation 出现此错误:

Throws: SQLException - if a database access error occurs, this method is called on a closed result set or the result set type is TYPE_FORWARD_ONLY SQLFeatureNotSupportedException - if the JDBC driver does not support this method

在同一页的前面,有一节介绍了结果集的 HSQL 特定详细信息。要调用 first,您需要修改语句创建:

ResultSet object generated by HSQLDB is by default of ResultSet.TYPE_FORWARD_ONLY (as is standard JDBC behavior) and does not allow the use of absolute and relative positioning methods. If a statement is created with:

Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

then the ResultSet objects it produces support using all of the absolute and relative positioning methods of JDBC2 to set the position of the current row...

但是你可能要想想为什么需要调用first.