Stored procedures:
Create or Replace procedure my_procedure (In_no in Number,in_name on VARCHAR2) is
Begin
INSERT into EMP (empno,ename) values (in_no,in_name);
End
Java Program Demo:
Import java.sql.CallableStatement;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import java.sql.SQLException;
Calling Oracle's stored procedures in Java
public class Javacallpro {
public static void Main (string[] args) {
String driver= "Oracle.jdbc.driver.OracleDriver";
String url= "JDBC:ORACLE:THIN:@127.0.0.1:1521:ORCL";
String user= "Scott";
String password= "Ztoracle";
try {
Class.forName (driver);
Connection c=drivermanager.getconnection (URL, user, password);
CallableStatement Cs=c.preparecall ("{Call My_procedure (?)}");
Cs.setint (1, 2121);
Cs.setstring (2, "Stephen Chow Chi");
Cs.execute ();
} catch (ClassNotFoundException e) {
throw new RuntimeException ();
} catch (SQLException e) {
}
}
}
Oracle PL/SQL Java calls Oracle-aware stored procedure