Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Q: jdbc and stored procedures returning several outparameters

Re: Q: jdbc and stored procedures returning several outparameters

From: Rauf Sarwar <rs_arwar_at_hotmail.com>
Date: 28 Sep 2005 03:48:16 -0700
Message-ID: <1127904496.412694.74370@o13g2000cwo.googlegroups.com>

Trond Kandal wrote:
> hello
>
> is there anyone who have used jdbc and stored procedures that
> returns more than one outparameter?
>
> i have looked at some examples from oracle but they uses only
> one outparameter.
>
> ex:
>
> CallableStatement cs = conn.prepareCall ("begin ? := foo(?); end;");
> cs.registerOutParameter(1,Types.CHAR);
> cs.setString(2, "aa");
> cs.executeUpdate();
> String result = cs.getString(1);
>
> how do i write the code when i want to get more than one
> outparameter?
>
> thanks!
>
>
> trond.
> --
> Trond Kandal Organisasjonsavd. voice: +47 73597497
> Integrasjonsgruppa NTNU mobile:+47 91897110
> IT-seksjonen 7491 Trondheim fax: +47 73598200
> http://www.itea.ntnu.no/integrasjon
>
> This is Unix land.
> In quiet nights you can hear M$-Windoze machines reboot.

SQL> create or replace procedure foo (out1 out varchar2, out2 out varchar2)
  2 is
  3 begin

  4     out1 := 'First OUT';
  5     out2 := 'Second OUT';

  6 end foo;
  7 /
Procedure created.

SQL> set serverout on
SQL> declare

  2     out1 varchar2(20);
  3     out2 varchar2(20);
  4  begin
  5     foo(out1, out2);
  6     dbms_output.put_line(out1);
  7     dbms_output.put_line(out2);

  8 end;
  9 /
First OUT
Second OUT

PL/SQL procedure successfully completed.

SQL> import java.sql.*;

public class Test {

   public static void main (String[] args)

      throws Exception {

      ......

      CallableStatement cs = conn.prepareCall ("begin foo(?,?); end;");

      cs.registerOutParameter(1,Types.CHAR);
      cs.registerOutParameter(2,Types.CHAR);
      cs.executeUpdate();

      System.out.println(cs.getString(1));
      System.out.println(cs.getString(2));

      cs.close();
      conn.close();

   }
}

C:\JavaDev\test>javac Test.java

C:\JavaDev\test>java Test
First OUT
Second OUT

Regards
/Rauf Received on Wed Sep 28 2005 - 05:48:16 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US