您的位置:首页 > 其它

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

2013-08-14 13:24 267 查看




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

}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: