使用CallableStatement处理Oracle数据库的存储过程
import java.sql.*;public class TestProc {
public static void main(String[] args) {
Connection conn = null;
CallableStatement cstmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:mgc", "system", "admin");
String sql = "{call p(?,?,?,?)}";
cstmt = conn.prepareCall(sql);
cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.registerOutParameter(4, Types.INTEGER);
cstmt.setInt(1, 6);
cstmt.setInt(2, 4);
cstmt.setInt(4, 0);
cstmt.execute();
System.out.println(cstmt.getInt(3));
System.out.println(cstmt.getInt(4));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (cstmt != null) {
cstmt.close();
cstmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
页:
[1]