我正在使用 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);
}
最佳答案
尝试使您的结果集可滚动:
PreparedStatement stmt= conn.prepareStatement("SELECT * FROM contacts",
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
我认为这应该可行
关于java - hsqldb 2.3.2 jdbc 驱动程序不支持 ResultSet.first()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30226467/