您的位置:首页 > 其它

Hibernate 调用存储过程 获取输出参数

2014-06-19 14:34 225 查看
创建存储过程

create or replace package test_mgmt is
--------src_template_id为输入参数,target_template_id为输出参数
procedure copy_temp(src_template_id number, src_template_name out varchar2);
end test_mgmt;

/

create or replace package body quality_mgmt is
procedure copy_temp(src_template_id number, src_template_name out varchar2) is
target_name varchar2(128);
begin
select t.name into target_name from t_qualitytemplate t where t.id = src_template_id;
src_template_name := target_name;
end copy_temp;
end quality_mgmt;

Hibernate调用存储过程

public Long doInHibernate(Session session) throws HibernateException, SQLException {
Connection c = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
CallableStatement cs = c.prepareCall("{call quality_mgmt.copy_quality_temp(?,?,?,?)}");
cs.setLong(1, qualTempId);
cs.setLong(2, areaId);
cs.setLong(3, creatorId);
//需要获取输出参数时,必须注册输出参数,否则直接条用cs.getInt(4)时会报索引列无效
cs.registerOutParameter(4, java.sql.Types.INTEGER);
cs.execute();
return new Long(cs.getInt(4));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: