db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rajesh Kartha <karth...@gmail.com>
Subject Re: How to get call a java procedure that returns a value?
Date Sat, 25 Mar 2006 21:23:50 GMT

Here is a very simple example of returning an INT from a Java Stored
Procedure:

In this case, the SP takes in an int and adds '100' to it.

Implementation:
---------------
public class MyProc {
public static void retIntegerValue(int i1[], int i3) {
i1[0]=i3+100;
}
}

Creating the Stored Procedure:
-------------------------------
drop procedure retIntVal;
CREATE PROCEDURE retIntVal(OUT a INT, IN b INT) PARAMETER STYLE JAVA
LANGUAGE JAVA EXTERNAL NAME 'MyProc.retIntegerValue';

Invoking it from your code:
----------------------------
CallableStatement op1 = connCS.prepareCall("CALL retIntVal(?, ?)");
op1.registerOutParameter(1, Types.INTEGER); //Important
op1.setInt(2,24); //Provide the input value
op1.execute();
int newi=op1.getInt(1);
System.out.println("New Int value = "+newi);

Output:
--------
New Int value = 124


More info available at:

http://wiki.apache.org/db-derby/DerbyInstruction

HTH

-Rajesh

Yan Ma wrote:

> Thx!
>
> ------------------
> 马燕
>
> 中科院软件所
> 通用软件实验室
>
> __________________________________________________
> 赶快注册雅虎超大容量免费邮箱?
> http://cn.mail.yahoo.com
>


Mime
View raw message