Search code examples
javajdbcresultset

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.


Solution

  • 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.