Re: JDBC3 and 7.4.1 - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: JDBC3 and 7.4.1
Date
Msg-id 40369EFC.9000700@opencloud.com
Whole thread Raw
In response to Re: JDBC3 and 7.4.1  (Ranjeet Kapur <ranjeet_kapur@yahoo.com>)
List 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

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: How do I ensure same session over multiple statements??
Next
From: "Michael Nonemacher"
Date:
Subject: JDBC statement batching in 7.4?