你可以在createStatement时使用光标类型,如:
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
// rs will be scrollable, will not show changes made by others然后就可以任意移动光标了,如:
rs.absolute(5); // moves the cursor to the fifth row of rs
具体的方法很多,请参见JAVADOC
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
// rs will be scrollable, will not show changes made by others然后就可以任意移动光标了,如:
rs.absolute(5); // moves the cursor to the fifth row of rs
具体的方法很多,请参见JAVADOC
rs.last();
再得到行号;
intRowCount = rs.getRow();
就得到记录数了。用rs.next()可以移到下一条记录。