pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Alex Wang <alex.wang@ebaotech.com>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Re: need advice about out parameter settings while calling stored procedure in Java code
Date: Sat, 01 Aug 2015 13:34:17 -0600
Message-ID: <55BD1F39.6090103@ttc-cmc.net> (raw)
In-Reply-To: <8cb5377a03194a98a1ce405ca75beb85@shmbx01.ebaotech.com>
References: <91b75bc23fbe41adba69c52ed4c2213f@shmbx01.ebaotech.com>
	<9d8eb7ea086c4bb7afd4408da5dfde74@shmbx01.ebaotech.com>
	<CADK3HHL3kUtyWppaK0HgzJtQDyMyPE0R+u3dgXTNcyicYf18yg@mail.gmail.com>
	<CAB=Je-FLhmQrROnROjp9TqqJ_FUJmTvdL2Wo0=XFHUqXaGDBwg@mail.gmail.com>
	<8cb5377a03194a98a1ce405ca75beb85@shmbx01.ebaotech.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Alex Wang wrote:
> Hi Vladimir/Dave,
>
> Thanks for your kind reply. I am migrating a huge platform from Oracle (11g) to
> Postgresql (Postgres Plus Advanced Server 9.3.1.3). Here are the details about
> the issue I encountered for your reference which I hope they are clear enough
> for your analysis.
>
> I have a stored procedure inside a package (/myPackage)/  whose SQL snippet  is:
>
> /PROCEDURE p_myprocedure(a character varying, b character varying, c character
> varying, d character varying, OUT o1 text, OUT o2 text) IS/
>
 > ~
 > ~
> ~
 >
 > Thanks & regards,
 > Alex

Hello Alex,

    I'm not sure and as John indicated that this report and fix is required
in this forum. The code example provided below works fine when used directly
with a 9.4.1 server installation and 9.4-1200.jdbc4. This was just recently
demostrated in this forum for meta data on CallableStatements.

The only difference is the FUNCTION rather then your PROCEDURE definition/
call.

danap.

Complete Workable Code Sample Method.

public void test(Connection connection)
    {
       // Method Instances
       String sqlStatementString;
       Statement sqlStatement;
       CallableStatement cstmt;

       try
       {
          sqlStatement = connection.createStatement();

          sqlStatementString = "CREATE OR REPLACE FUNCTION sum_n_product(x int, 
y int, OUT sum int, OUT prod int) AS $$"
                + " SELECT (x + y) AS sum, (x * y) AS prod; $$ LANGUAGE SQL;";
          System.out.println(sqlStatement);
          sqlStatement.execute(sqlStatementString);

          // Execute Function.

          cstmt = connection.prepareCall("{call sum_n_product(?,?,?,?)}");

          cstmt.registerOutParameter(3, Types.INTEGER);
          cstmt.registerOutParameter(4, Types.INTEGER);

          cstmt.setInt(1, 2);
          cstmt.setInt(2, 5);

          cstmt.execute();

          int x1 = cstmt.getInt(3);
          int x2 = cstmt.getInt(4);

          System.out.println("x1: " + x1);
          System.out.println("x2: " + x2);

          // Drop Function.
          sqlStatementString = "DROP FUNCTION sum_n_product(int, int, OUT int, 
OUT int);";
          System.out.println(sqlStatementString);
          sqlStatement.execute(sqlStatementString);

          cstmt.close();
          sqlStatement.close();
       }
       catch (SQLException sqle)
       {
          System.out.println("SQL Exeception" + sqle);
       }
    }







-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (8+ messages)

Message-ID: <55BD1F39.6090103@ttc-cmc.net>
Permalink:  ../55BD1F39.6090103@ttc-cmc.net/
Also on:    postgresql.org/message-id/55BD1F39.6090103@ttc-cmc.net

 · 

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: danap@ttc-cmc.net, alex.wang@ebaotech.com
  Subject: Re: need advice about out parameter settings while calling stored procedure in Java code
  In-Reply-To: <55BD1F39.6090103@ttc-cmc.net>
  References: <91b75bc23fbe41adba69c52ed4c2213f@shmbx01.ebaotech.com> <9d8eb7ea086c4bb7afd4408da5dfde74@shmbx01.ebaotech.com> <CADK3HHL3kUtyWppaK0HgzJtQDyMyPE0R+u3dgXTNcyicYf18yg@mail.gmail.com> <CAB=Je-FLhmQrROnROjp9TqqJ_FUJmTvdL2Wo0=XFHUqXaGDBwg@mail.gmail.com> <8cb5377a03194a98a1ce405ca75beb85@shmbx01.ebaotech.com> <55BD1F39.6090103@ttc-cmc.net>

* 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