我一直在制作一个使用 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/