try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee", "root", "root");
String query = "select * from sample;";
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.executeQuery(query);
ResultSet rs = stmt.getResultSet();
rs.absolute(3);
while (rs.next()) {
System.out.println(rs.getString("name"));
}
rs.beforeFirst();
while (rs.next()) {
System.out.println(rs.getString("name"));
}
while (rs.previous()) {
System.out.println(rs.getString("name"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
这工作正常。这ResultSet
是TYPE_FORWARD_ONLY
但我也可以朝前一个方向前进。谁能解释一下,我用谷歌搜索,但没有得到任何满意的答案。