CallableStmtDemo.java :
public class CallableStmtDemo {
public static void main(String[] args) {
callSpWithOutParam();
}
public static void callSpWithOutParam(){
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.
getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
CallableStatement callStmt=conn.prepareCall("{call total_count(?,?)}");
callStmt.setInt(1,20);
callStmt.registerOutParameter(2,Types.INTEGER);//重点
callStmt.execute();
int n=callStmt.getInt(2);
System.out.println("部门20有"+n+"个员工");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}