DEVFYI - Developer Resource - FYI

There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

JDBC Interview Questions and Answers


(Continued from previous question...)

There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

No, but it is easy to find the number of rows. If you are using a scrollable result set, rs, you can call the methods rs.last and then rs.getRow to find out how many rows rs has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT column in the SELECT clause.

(Continued on next question...)

Other Interview Questions