X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0CE5E534CF; Fri, 25 Mar 2005 00:46:45 +0000 (GMT) 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 24170-06; Fri, 25 Mar 2005 00:46:44 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id D29F35324A; Fri, 25 Mar 2005 00:46:42 +0000 (GMT) Received: from [192.168.1.100] ([24.202.23.128]) by VL-MO-MR011.ip.videotron.ca (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0IDV0092AU4CEI@VL-MO-MR011.ip.videotron.ca>; Thu, 24 Mar 2005 19:45:48 -0500 (EST) Date: Thu, 24 Mar 2005 19:49:07 -0500 From: David Gagnon Subject: Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How to In-reply-to: To: Kris Jurka Cc: pgsql-jdbc@postgresql.org, pgsql-general@postgresql.org Message-id: <42436003.3000509@siunik.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) References: <42434D89.5080104@siunik.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.016 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/1237 X-Sequence-Number: 75552 Hi Kris, I don't get error with the rsTmp.close() statement but with " (rsTmp.next()) ". The arraycopy is because I want to shrink the original array (size 50) to it real size. It's not intended to be a deep copy. Plpgsql function can return multiple refcursor .. so the question is how I can get them via JDBC? Below I included the function that doen't work (throw exception in the while condition). I also included a "WORKING" function that actually return only one refcursor. Thanks for your help .. if you see something wrong I'll be happy to know it :-) /David public ResultSet[] executePreparedStatementQueryMultipleCursor() throws SQLException { ResultSet rsTmp = ps.executeQuery(); ResultSet[] tempArray = new ResultSet[50]; // Should be enough int j = 0; while (rsTmp.next()) { tempArray[j] = (ResultSet) rsTmp.getObject(1); j++; } rs = new ResultSet[j]; System.arraycopy(tempArray, 0, rs, 0, j); rsTmp.close(); return rs; } public ResultSet executePreparedStatementQueryCursor() throws SQLException { ResultSet rsTmp = ps.executeQuery(); rs = new ResultSet[1]; rs[0] = (ResultSet) rsTmp.getObject(1); rsTmp.close(); return rs[0]; } Kris Jurka wrote: >On Thu, 24 Mar 2005, David Gagnon wrote: > > > >> I'm already able to get Refcursor from a stored procedure. But now I >>need to get a SETOF refcursor and I can't make it work... Is that >>possible to do this via JDBC? >> >>He is the code I did. The rsTmp.next() throws a Connection is >>closed. Operation is not permitted. Exception. >> >> >> rs = new ResultSet[j]; >> System.arraycopy(tempArray, 0, rs, 0, j); >> rsTmp.close(); >> >> > >System.arraycopy does not make a deep copy, so the rsTmp.close() closes >the ResultSet. You really can't copy resources around like that. >Consider how you would copy a Connection object. Does that establish a >new connection? The underlying tcp/ip connection can't be copied. > >Kris Jurka > > > >