I want to get the row count of a ResultSet
.
ResultSet rs;
Statement s;
rs=s.executeQuery("SELECT * FROM mytable");
//rs.getRowCount; ???
I want to get the row count of a ResultSet
.
ResultSet rs;
Statement s;
rs=s.executeQuery("SELECT * FROM mytable");
//rs.getRowCount; ???
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
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()