pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James Ireland <james@halfcab.com>
To: pgsql-jdbc@postgresql.org
Subject: Fetching rows from a cursor returned by a stored function
Date: Fri, 17 Sep 2004 16:15:57 +0100
Message-ID: <414AFFAD.6040404@halfcab.com> (raw)

Hi everybody

I have a stored function that returns a large number of rows as a cursor.  I am trying to prevent the entire result set being returned at once.  The code fragment below hits an OutOfMemoryError on the "while(resultSet.next())" line, which I believe is for this reason.  


    // ...get connection...

    connection.setAutoCommit(false);
  
    // prepare the stored function call
    statement = connection.prepareCall("{ ? = call get_events(?,?,?) }", 
            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    statement.registerOutParameter(1, Types.OTHER);

    // set the fetch size so that the query doesn't return all results at once
    statement.setFetchDirection(ResultSet.FETCH_FORWARD);
    statement.setFetchSize(1000);
              
    // execute the query
    statement.execute();
    resultSet = (ResultSet)statement.getObject(1);
    
    while(resultSet.next()) {

        // ...process rows...


The code includes my first attempt to make this work by setting the fetch size.  This still doesn't fix it, and I can see that the result set that I am setting the fetch size for probably isn't the one that I am getting back and iterating through.  I can't figure out how I ought to be doing this though.

Can anyone offer any advice on how this should be done?

Many thanks
-James



view thread (4+ messages)  latest in thread

Message-ID: <414AFFAD.6040404@halfcab.com>
Permalink:  ../414AFFAD.6040404@halfcab.com/
Also on:    postgresql.org/message-id/414AFFAD.6040404@halfcab.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: james@halfcab.com
  Subject: Re: Fetching rows from a cursor returned by a stored function
  In-Reply-To: <414AFFAD.6040404@halfcab.com>
  References: <414AFFAD.6040404@halfcab.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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