pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Leo Martin Orfei <orfeileo@yahoo.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: problems returning a resultset from a function
Date: Sat, 11 Sep 2004 08:23:48 -0700 (PDT)
Message-ID: <20040911152348.19135.qmail@web51802.mail.yahoo.com> (raw)
In-Reply-To: <4142ABFC.6020401@opencloud.com>

Thanks a lot.
This really solve my problem.

regards.

--- Oliver Jowett <oliver@opencloud.com> wrote:

> Leo Martin Orfei wrote:
> 
> [.. declare function returning refcursor ..]
> 
> > CallableStatement cs = null;
> > ResultSet rs = null;
> > cs = con.prepareCall("{ ? = call test()}");
> > cs.registerOutParameter(1, java.sql.Types.OTHER);
> > rs = cs.executeQuery();
> > rs.next();
> > System.out.println("name: " +rs.getString(1));
> > 
> > but throws te following error:
> > 
> > cursor "<unnamed portal 1>" does not exist
> 
> Check that you have called
> Connection.setAutoCommit(false). If 
> autocommit is on, your returned cursor will be
> closed as soon as the 
> transaction (auto)commits, so the subsequent select
> done to fetch the 
> portal contents will fail.
> 
> A '? = call' escape does not return a resultset. You
> should use the 
> CallableStatement.get...() methods to retrieve the
> values of the out 
> parameter. You will likely see errors complaining
> about no resultset 
> being returned from executeQuery() once you fix the
> autocommit setting.
> 
> The refcursor is returned as a ResultSet (as the
> out-parameter value) 
> i.e. CallableStatement.getObject(1) will return a
> ResultSet that has the 
> contents of the refcursor.
> 
> See
>
http://www.postgresql.org/docs/current/static/jdbc-callproc.html
> for 
> some example code on using callable statements and
> refcursor-returning 
> functions. (note that using PGRefCursorResultSet is
> deprecated; just use 
> getString() to obtain the cursor name).
> 
> -O
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



view thread (4+ messages)  latest in thread

Message-ID: <20040911152348.19135.qmail@web51802.mail.yahoo.com>
Permalink:  ../20040911152348.19135.qmail@web51802.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040911152348.19135.qmail@web51802.mail.yahoo.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: orfeileo@yahoo.com, oliver@opencloud.com
  Subject: Re: problems returning a resultset from a function
  In-Reply-To: <20040911152348.19135.qmail@web51802.mail.yahoo.com>
  References: <4142ABFC.6020401@opencloud.com> <20040911152348.19135.qmail@web51802.mail.yahoo.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