jdbc调用有参数输出的存储过程

jdbc调用有参数输出的存储过程_第1张图片

jdbc调用有参数输出的存储过程_第2张图片

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();
		}
		
	}
}




你可能感兴趣的:(JDBC)