Below is a small example of a java Program calling oracle Stored Proc.
May be this can help you
import java.util.Properties;
import java.sql.Driver;
import java.sql.Connection;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.lang.Integer;
import oracle.jdbc.OracleTypes;
public class CallProc
{
public static void main(String[] args)
{
Properties props = new java.util.Properties();
props.put("user", "SCOTT");
props.put("password", "TIGER");
try
{
Driver d = (Driver)Class.forName
("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = d.connect
("jdbc:oracle:thin:@localhost:1521:efg8ir3", props);
String sProc = "begin ? := MySquare(?); end;";
CallableStatement stmt = conn.prepareCall
(sProc);
// register the type of the out param - an
Oracle specific type
stmt.registerOutParameter(1,
OracleTypes.INTEGER);
// set the in param
stmt.setInt(2, 5);// Float(2, price);
// execute and retrieve the result set
stmt.execute();
//Integer im = (Integer)stmt.getObject(1);
//System.out.println(im.intValue());
System.out.println(stmt.getInt(1));
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
The code for oracle stored proc is
CREATE OR REPLACE FUNCTION MySquare(i number)
RETURN number
AS
BEGIN
RETURN i * i;
END;