Liz said:
I'm just starting to use JDBC and want
to know the number of rows in a result set
but have not been able to figure it out.
JDBC allows the driver to read the results in chunks. That means, that
the driver needs not to read the complete result set at once. This is
important due to perfomance and economical memory management. On the
other hand that means, that there's no way to know the number of all
records in advance.
How comfortable you can determine the record count depends on the type
of your ResultSet.
If your ResultSet is scrollable (not of type TYPE_FORWARD_ONLY), then
you may use absolute positioning, that is for a given ResultSet rs
rs.last();
int i = rs.getRow();
If your ResultSet isn't scrollable, then you have to walk through it:
int i = 0;
while ( rs.next() )
i++;
But if your ResultSet isn't scrollable, you can't return back, so you
would have to execute the query twice if you want to know the number of
records before processing the results.
Bye
Michael