pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Zenz <robert.zenz@sibvisions.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Out parameters for functions.
Date: Wed, 19 Sep 2018 14:42:50 +0000
Message-ID: <5BA2606B.60607@sibvisions.com> (raw)

Hello everybody.

We've recently had to use functions which used OUT parameters and we are a
little bit confused regarding the handling of such. In other JDBC drivers one
does simply register the OUT parameter at the appropriate position in the
parameter list. However, with the PostgreSQL JDBC driver we had to skip the
registration of the OUT parameter altogether, the return value for the OUT
parameter is then returned *after* all other parameters.

Example, there is function which does accept three parameters:

 1. IN numeric
 2. OUT varchar
 3. INOUT timezone

When calling this function we have to do the following:

    CallableStatement statement = connection.prepareCall("{ ? = call test(?, ?) }");
    statement.registerOutParameter(1, Types.NUMERIC); // Return value.
    statement.setObject(2, value); // IN numeric
    statement.setObject(3, value); // INOUT timezone

    statement.execute();

    statement.getObject(4); // OUT varchar

This is a little bit confusing at first, is that intended to behave as such?

view thread (6+ messages)  latest in thread

Message-ID: <5BA2606B.60607@sibvisions.com>
Permalink:  ../5BA2606B.60607@sibvisions.com/
Also on:    postgresql.org/message-id/5BA2606B.60607@sibvisions.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: robert.zenz@sibvisions.com
  Subject: Re: Out parameters for functions.
  In-Reply-To: <5BA2606B.60607@sibvisions.com>
  References: <5BA2606B.60607@sibvisions.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