jdbc-example-Stored procedure
In this example we will see how to call the Stored procedure
have some in parameters,out parameter.
create Stored procedure :
create or replace procedure procthree(pone IN number,ptwo
IN number,pthree OUT number)
as
BEGIN
pthree:=pone+ptwo;
end procthree;
/
jdbc code using above Stored procedure example:
import java.sql.*;
class SP3
{
public static void main(String[] args) throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
System.out.println(" Connected 2 DB.....");
CallableStatement cstmt=con.prepareCall("{call procthree(?,?,?)}");
cstmt.setInt(1,12);
cstmt.setInt(2,22);
// Register out parameter
cstmt.registerOutParameter(3,Types.INTEGER);
// Execute the call.
cstmt.execute();
System.out.println(cstmt.getInt(3)); //34
}
}
0 comments:
Post a Comment