Re: JDBC3 and 7.4.1

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Ranjeet Kapur <ranjeet_kapur(at)yahoo(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JDBC3 and 7.4.1
Date: 2004-02-20 23:57:48
Message-ID: 40369EFC.9000700@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ranjeet Kapur wrote:
> Thanks, I just did a few experiments and found the same thing, that
> getFetchSize() was returning 0. Is there anything else I could use to
> achieve the same result, namely how many rows in the select ?? I am very
> new to DB programming that´s why I probably misread the documentation on
> getFetchSize().

Add a COUNT(*) to the query, if you can; then the count will appear as a
column in your resultset.

Alternatively:

Statement stmt =
connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(query);

// Count rows.
rs.last();
int resultSetSize = rs.getRow();

// Process actual resultset
rs.beforeFirst();
while (rs.next()) {
// do stuff
}

but this requires iterating over the resultset twice, and using
TYPE_SCROLL_INSENSITIVE prevents the current driver from using cursors
to incrementally fetch data, so you will have the entire resultset in
memory on the Java side.

If you don't need the total count before processing the resultset, just
count as you process each result row (then you don't need a
TYPE_SCROLL_INSENSITIVE ResultSet, either).

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2004-02-21 00:04:40 Re: How do I ensure same session over multiple statements??
Previous Message Sean Shanny 2004-02-20 22:27:32 How do I ensure same session over multiple statements??