Getting the count of rows in a Java resultset
Posted
by Mr Morgan
on Stack Overflow
See other posts from Stack Overflow
or by Mr Morgan
Published on 2010-06-16T11:11:05Z
Indexed on
2010/06/16
11:12 UTC
Read the original article
Hit count: 408
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.
© Stack Overflow or respective owner