Thread: ResultSet & setFetchSize fails to stop heap failures

ResultSet & setFetchSize fails to stop heap failures

From
"U. George"
Date:
The resultset is a very large  set of rows  ( each row 2 ints and a
bunch of doubles ) .  I am unable to  convince jdbc to fetch one row at
a time, and avoid the heap failure.
Is there a way, or just a bug, or feature deficiency?

        String s = "Select tzids, tzide, latlonpoints from " + tableName;
        ResultSet rSet;
        try {
            Statement select = sqlConnection.createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            select.setFetchSize( 1 );
            rSet = select.executeQuery(s);      <==========================
            rSet.setFetchSize(1);
        } catch ( Exception e ) { e.printStackTrace(); rSet = null; }



Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:235)
        at UpdateNodeNumbers.getAllTzid(UpdateNodeNumbers.java:78)
        at UpdateNodeNumbers.<init>(UpdateNodeNumbers.java:34)
        at TestShapefile.test(TestShapefile.java:63)
        at TestShapefile.main(TestShapefile.java:50)



Re: ResultSet & setFetchSize fails to stop heap failures

From
Kris Jurka
Date:

On Wed, 28 May 2008, U. George wrote:

> The resultset is a very large  set of rows  ( each row 2 ints and a
> bunch of doubles ) .  I am unable to  convince jdbc to fetch one row at
> a time, and avoid the heap failure.
> Is there a way, or just a bug, or feature deficiency?

To do partial fetches you must turn autocommit off.  See:

http://jdbc.postgresql.org/documentation/83/query.html#query-with-cursor

Kris Jurka



Re: ResultSet & setFetchSize fails to stop heap failures

From
"U. George"
Date:
To do partial fetches you must turn autocommit off.  See:
>
> http://jdbc.postgresql.org/documentation/83/query.html#query-with-cursor
>
> Kris Jurka
Yup, that did it.  I suppose there is a reason why no exception is
thrown at the execute, or an error for the setFetchSize when autocommit
is still on?

Re: ResultSet & setFetchSize fails to stop heap failures

From
Kris Jurka
Date:

On Wed, 28 May 2008, U. George wrote:

>> To do partial fetches you must turn autocommit off.  See:
>>
>
> Yup, that did it.  I suppose there is a reason why no exception is
> thrown at the execute, or an error for the setFetchSize when autocommit
> is still on?
>

You can't throw an exception at setFetchSize because you could do
setFetchSize(N) and then setAutoCommit(false).  Throwing an exception at
execute time is possible, but I don't think the driver should.  Fetch size
is just a hint, so it's not a failure if it isn't used.

Kris Jurka