Java HSQLDB 连接问题

标签 java hsqldb

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

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 特定详细信息的部分。要首先调用,您需要修改语句创建:

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

但是您可能想考虑为什么需要首先调用

关于Java HSQLDB 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35136758/

相关文章:

java - 如何在纯内存模式下运行 HSQLDB 服务器

java - 使用 HSQLDB 数据库的 Tomcat 部署应用程序给出 JDBCConnectionException

java - 我可以使用 HSQLDB 进行 junit 测试克隆 mySQL 数据库吗

java - 如何使用 JUnit 测试对象数组

javascript - 如何查找youtube url是Java中的 channel 还是播放列表

java - java comparable上的排序算法问题

java - 使用 Struts2 taglib 通过 URL 将参数传递给操作

java - 在 Eclipse 中将 java double 更改为 float

java - 如何禁用 Hibernate 4.0 日志记录?

java - 我应该将哪种嵌入式 RDBMS 与 Java 结合使用?为什么?备份和维护呢?