您的位置:首页 > 数据库 > Oracle

hibernate调用oracle存储过程案列

2016-07-11 22:46 387 查看
create or replace procedure province_test(pro_name in varchar,pro_count out int) is
begin
select count(id) into pro_count from s_city where pid=(select id from s_province where name=pro_name);
end;
try {
Connection conn = SessionFactoryUtils.getDataSource(this.getSessionFactory()).getConnection();//得到jdbc Connection
CallableStatement cstmt = conn.prepareCall("{call province_test(?,?)}");//调用存储过程
cstmt.setString(1, pname);//in参数
cstmt.registerOutParameter(2, Types.INTEGER);//out参数
cstmt.execute();
return cstmt.getInt(2);//得到2位置的out值
} catch (SQLException e) {
e.printStackTrace();
return 0;
}





参考链接:https://docs.oracle.com/cd/B28359_01/java.111/b31224/getsta.htm#i1014127
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: