Thread: Nmber of rows in a ResultSet

Nmber of rows in a ResultSet

From
"Xavier Bugaud"
Date:
Hi all,

JDBC does not allow to directly retrieve the number of rows in a
ResultSet.
However, in old Postgres JDBC drivers (pgjdbc2.jar), the number of rows
contained in a ResultSet could be obtained by calling getFetchSize().

In the last JDBC drivers, is there a means to get the number of rows
directly (without using 'SELECT COUNT(*)' or 'rs.last();rs.getrow();') ?

Thank you in advance.

Regards
--
Xavier Bugaud
www.gloptv.com


Re: Nmber of rows in a ResultSet

From
Kris Jurka
Date:

On Fri, 9 Jan 2004, Xavier Bugaud wrote:

> Hi all,
>
> JDBC does not allow to directly retrieve the number of rows in a
> ResultSet.
> However, in old Postgres JDBC drivers (pgjdbc2.jar), the number of rows
> contained in a ResultSet could be obtained by calling getFetchSize().

This was just an implementation artifact and the javadoc for the method
should have made you wary of using it in the way you are.

> In the last JDBC drivers, is there a means to get the number of rows
> directly (without using 'SELECT COUNT(*)' or 'rs.last();rs.getrow();') ?

I don't see what's so wrong with rs.last() and rs.getRow().

Kris Jurka