Re: Number of rows in a ResultSet ?

From: Michael Stephenson <mstephenson(at)tirin(dot)openworld(dot)co(dot)uk>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: Number of rows in a ResultSet ?
Date: 2001-01-18 14:42:06
Message-ID: Pine.LNX.4.30.0101181434130.2688-100000@tirin.openworld.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

> I need to know how many rows exist in a ResultSet. I've tried to use
> getFetchSize() method of ResultSet interface, but a message was
> displayed "this method is not yet implemented".
>
> Anyone can help me ?

You could use:
ResultSet.last();
int numberOfRows = ResultSet.getRow();

Now, my understanding of this area is a but sketchy, but I think that
most implementations of ResultSet do not get all of the results in one go
(like the PostgreSQL JDBC driver does), so getFetchSize() is not a safe
way of determining the number of results returned.

Or, you could do another query with count() in your sql..

Or (and I wouldn't do this without carefully looking at the jdbc spec),
you could just alter the getFetchSize() method
org.postgresql.jdbc2.ResultSet driver to look like:

public int getFetchSize() throws SQLException
{
return rows.size();
}

The choice is yours..

Michael Stephenson mstephenson(at)openworld(dot)co(dot)uk
Developer - Web Applications - Open World
Tel: +44 1225 444 950 Fax: +44 1225 336 738

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter T Mount 2001-01-18 15:23:07 Re: Number of rows in a ResultSet ?
Previous Message The Hermit Hacker 2001-01-18 13:53:14 Re: [RFC] Proposed split of -interfaces list ...