建立存储过程(无返回值的)
CREATE OR REPLACE PROCEDURE TEST002p(PARA1 IN VARCHAR2,PARA2 IN VARCHAR2) AS
BEGIN
INSERT INTO test002 (ID,NAME) VALUES (PARA1, PARA2);
END TEST002p;
JAVA JDBC调用
package cn.yu.PROCEDURE;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class procedureDemo {
public procedureDemo() {
}
public static void main(String[] args) {
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521: ora12 ";
ResultSet rs = null;
Connection conn = null;
CallableStatement cstmt = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "oliver", "123");
cstmt= conn.prepareCall("{ call TEST002p(?,?) }");
cstmt.setString(1, "105");
cstmt.setString(2, "adsfasdf");
cstmt.execute();
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
catch (Exception ex2) {
ex2.printStackTrace();
}
finally {
try {
if (rs != null) {
rs.close();
if (conn != null) {
conn.close();
}
}
}
catch (SQLException ex1) {
}
}
}
}
建立表TEST002以及字段ID,NAME