Re: Callable Statements - Mailing list pgsql-jdbc

From Nic Ferrier
Subject Re: Callable Statements
Date
Msg-id 87wui3lu4t.fsf@pooh-sticks-bridge.tapsellferrier.co.uk
Whole thread Raw
In response to Callable Statements  (Mark French <frenchmb@tpg.com.au>)
List pgsql-jdbc
Mark French <frenchmb@tpg.com.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

pgsql-jdbc by date:

Previous
From: floess@mindspring.com
Date:
Subject: Re: Callable Statements
Next
From: Nic Ferrier
Date:
Subject: Re: Callable Statements