pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Number of rows in a ResultSet ?
3+ messages / 3 participants
[nested] [flat]

* Number of rows in a ResultSet ?
@ 2001-01-17 11:37  Thierry Dart <dart@u444.jussieu.fr>
  0 siblings, 1 reply; 3+ messages in thread

From: Thierry Dart @ 2001-01-17 11:37 UTC (permalink / raw)

Hello

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 ?

Thierry



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Number of rows in a ResultSet ?
@ 2001-01-18 14:42  Michael Stephenson <mstephenson@tirin.openworld.co.uk>
  parent: Thierry Dart <dart@u444.jussieu.fr>
  0 siblings, 1 reply; 3+ messages in thread

From: Michael Stephenson @ 2001-01-18 14:42 UTC (permalink / raw)
  To: 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@openworld.co.uk
Developer   -    Web Applications    -   Open World
Tel: +44 1225 444 950         Fax: +44 1225 336 738




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Number of rows in a ResultSet ?
@ 2001-01-18 15:23  Peter T Mount <peter@retep.org.uk>
  parent: Michael Stephenson <mstephenson@tirin.openworld.co.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Peter T Mount @ 2001-01-18 15:23 UTC (permalink / raw)
  To: Michael Stephenson <mstephenson@tirin.openworld.co.uk>; +Cc: pgsql-interfaces

Quoting Michael Stephenson <mstephenson@tirin.openworld.co.uk>:

> > 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.

Until about 30 minutes ago getFetchSize() threw an SQLException as it wasn't 
implemented ;-)

For normal ResultSet's in 7.1 getFetchSize() will return the number of rows, 
but I'd advise you use Michael's suggestion as it's probably the safest bet for 
TYPE_SCROLL_INSENSITIVE & TYPE_SCROLL_SENSITIVE ResultSets (remember 
technically TYPE_FORWARD_ONLY ResultSet's should not allow you to go back after 
the .last() call).

Peter
> 
> 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@openworld.co.uk
> Developer   -    Web Applications    -   Open World
> Tel: +44 1225 444 950         Fax: +44 1225 336 738
> 
> 



-- 
Peter Mount peter@retep.org.uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-01-18 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-17 11:37 Number of rows in a ResultSet ? Thierry Dart <dart@u444.jussieu.fr>
2001-01-18 14:42 ` Michael Stephenson <mstephenson@tirin.openworld.co.uk>
2001-01-18 15:23   ` Peter T Mount <peter@retep.org.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox