Hi,
> Hi,
>
> how can i get the number of rows returned by
> PreparedStatement s = "...";
> ResultSet r = s.executeQuery();
>
> I currently use
> int count;
> if (r.isAfterLast())
> count = 0;
This is wrong, as JDBC says for isAfterLast:
Returns true if the cursor is after the last row; false
if the cursor is at any other position or the result set contains
no rows.
Also, if there are no rows, getRow() returns 0 immediately, and calling 'last' does
not harm.
> else
> {
> r.last();
> count = r.getRow();
> }
>
> My hope is, that last() instructs the kernel to move the
> cursor to the
> last row, and therefor the traffic won't be that much.
Yes, but *only* this. Actually calling 'getRow' while being
on the 'last' row uses some tricks, which may or may not
be performant enough. Its performance depends heavily on
the particular strategy chosen by the database to create
the result, and what you have done on the result before.
(Fetching through the result, and afterwards using that
sequence above is quite more performant as doing it as
first operation).
> Is there a more sapdb-optimized version to get the number of rows
> returned by a select-statement?
No. If you look at other DBMS', you will see that getRow() is
always relatively expensive.
If you want only the number, there is no need for selecting the
data => use a "SELECT COUNT(...) ...",
if you need to handle the data you have to live with the fact that
DBMS usually only know the result count when they have built up
the result completely.
Regards
Alexander Schröder
SAP Labs Berlin
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general