Invoking Oracle's stored procedures and JDBC operations in Java is similar to the following steps
1: Load Driver
2: Link database and get a database link object
3: Execute statement
4: Operation result set
5: Close Resource
The premise is that the stored procedure is written.
Create or replace procedure My_procedure is
Begin
INSERT into EMP (empno,ename) VALUES (9527, ' Tong Pak Fu ');
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.execute ();
} catch (ClassNotFoundException e) {
throw new RuntimeException ();
} catch (SQLException e) {
}
}
}
The above program does not close the resources and so on, just a simple demo
Oracle PL/SQL calls non-parametric Oracle stored procedures in Java