Getting the count of rows in a Java resultset
- by Mr Morgan
Hello
Does anyone know a better way of getting the number of rows in a Java resultset returned from a MySQL database?
I'm currently using this:
public static int getResultSetRowCount(ResultSet resultSet) {
int size = 0;
try {
resultSet.last();
size = resultSet.getRow();
resultSet.beforeFirst();
}
catch(Exception ex) {
return 0;
}
return size;
}
But am open to alternatives.
The resultset returned is not going to be the total number of rows read from the database so I don;t think I can use SQL COUNT.
Thanks
Mr Morgan.