Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find number of records in ResultSet

I am getting ResultSet after an Oracle query. when I iterating through the ResultSet its going in infinite loop.

ResultSet rs = (ResultSet) // getting from statement
while (rs.next()) {
//
//
}

this loop is not terminating so I tried finding number of records using rs.getFetchSize() and its returning a value 10. I want to know if this is the correct method to find out number of records in ResultSet and if the count is 10 why is it going in infinite loop. Please give your opinion.

like image 317
dku.rajkumar Avatar asked Dec 01 '11 08:12

dku.rajkumar


People also ask

How do you count records in Java?

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.

Which command is used for counting the number of rows in the ResultSet?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

Which function returns the number of rows in a ResultSet?

The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values.


1 Answers

Actually, the ResultSet doesn't have a clue about the real number of rows it will return. In fact, using a hierachical query or a pipelined function, the number might as well be infinite. 10 is the suggested number of rows that the resultset should/will try to fetch in a single operation. (see comment below).

It's best to check your query, if it returns more rows than you expect.

like image 112
Erich Kitzmueller Avatar answered Oct 27 '22 00:10

Erich Kitzmueller