问题
I want to get the row count of a ResultSet.
ResultSet rs;
Statement s;
rs=s.executeQuery("SELECT * FROM mytable");
//rs.getRowCount; ???
回答1:
You can go to the last row of the resultset and get the row number like this:
resultSet.last()
int count = resultSet.getRow()
But this is inefficient because it has to read all the table data. Better to execute the query:
SELECT COUNT(*) FROM mytable
回答2:
I think we can get count as given below:
int size = 0;
try {
while(rs.next()){
size++;
}
}
catch(Exception ex) { }
or we can use
ResultSet.getRow()
来源:https://stackoverflow.com/questions/25351452/how-get-the-number-of-rows-count-by-resultset-in-java