X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B02D0329DF7 for ; Fri, 17 Sep 2004 16:15:54 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03612-09 for ; Fri, 17 Sep 2004 15:15:51 +0000 (GMT) Received: from blackcomb.delosis.com (blackcomb.delosis.com [193.201.201.182]) by svr1.postgresql.org (Postfix) with ESMTP id 9012E329DBF for ; Fri, 17 Sep 2004 16:15:50 +0100 (BST) Received: from [84.9.10.14] (helo=[127.0.0.1]) by blackcomb.delosis.com with asmtp (Cipher TLSv1:RC4-MD5:128) (Exim 3.35 #1 (Debian)) id 1C8KSi-0008MT-00 for ; Fri, 17 Sep 2004 16:15:48 +0100 Message-ID: <414AFFAD.6040404@halfcab.com> Date: Fri, 17 Sep 2004 16:15:57 +0100 From: James Ireland User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Fetching rows from a cursor returned by a stored function Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/86 X-Sequence-Number: 10976 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