Re: Callable Statements

From: Nic Ferrier <nferrier(at)tapsellferrier(dot)co(dot)uk>
To: Mark French <frenchmb(at)tpg(dot)com(dot)au>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Callable Statements
Date: 2003-04-09 12:42:26
Message-ID: 87wui3lu4t.fsf@pooh-sticks-bridge.tapsellferrier.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Mark French <frenchmb(at)tpg(dot)com(dot)au> writes:

> Hi,
>
> I'm new to postgres JDBC and was wondering if it supported callable
> statements at all? The documentation doesn't have any examples and
> would like to know it was possible to use them to call functions that
> return multiple rows? An example would be greatly appreciated.
>

The CVS version of PG implements CallableStatements that can return
multiple rows.

Do it like this:

try
{
CallableStatement proc
= con.prepareCall("{ ? = call someproc (?) }");
proc.registerOutParameter(1, Types.OTHER);
proc.setInt(2, 1);
proc.execute();
ResultSet rs = (ResultSet) proc.getObject(1);
while (rs.next())
{
System.out.println("ha!");
}
con.close();
}

The proc should return a ref cursor type, much like it would in
Oracle. The PL/PGSQL manual explains how to do that.

Nic

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nic Ferrier 2003-04-09 12:45:06 Re: Callable Statements
Previous Message floess 2003-04-09 12:34:43 Re: Callable Statements