Getting the Number of Rows in a Table Using a Scrollable Result Set
This example gets the number of rows in a scrollable result set by
moving the cursor to the last row of the result set and then calling
ResultSet.getRow().
try {
// Create a scrollable result set
Statement stmt = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
// Move to the end of the result set
resultSet.last();
// Get the row number of the last row which is also the row count
int rowCount = resultSet.getRow();
} catch (SQLException e) {
}
Post a comment