网站首页 > 网络编程教程 > Java教程 > 在Hibernate中用jdbc做存储过程

在Hibernate中用jdbc做存储过程

  • 作者:互联网
  • 时间:2009-12-18 17:46:22

package co***xtc.bi.app.crm.rep.dao.impl;

import ja***sql.CallableStatement;
import ja***sql.Connection;
import ja***sql.ResultSet;
import ja***sql.SQLException;

import ja***.sql.DataSource;

import or***pringframework.orm.hibernate3.SessionFactoryUtils;
import or***pringframework.orm.hibernate3.support.HibernateDaoSupport;
/**
*
*


* Title:在hibernate中用存储过程
* 只是要绕过hibernate   调用jdbc   API,当然事务还是由hibernate业管理:
假如我们创建了以下存储过程:
create   or   replace   procedure   batchUpdateCustomer(p_age   in   number)   as    
begin    
update   CUSTOMERS   set   AGE=AGE+1   where   AGE> p_age;    
end;    


存储过程中有一个参数p_age,代表客户的年龄,应用程序可按照以下方式调用存储过程:
* Description: 程序功能的描述
*


* @author   lichunmei li***sagessesoft.com">li***sagessesoft.com
* @version 1.00.00
*

* 修改记录
*    修改后版本:     修改人:  修改日期:     修改内容:
*

*/
public class Text extends HibernateDaoSupport {
public void  proceduce(){
 
   try {
    DataSource ds= Se***onFactoryUtils.getDataSource(getSessionFactory());
    Connection  co***ds.getConnection();
    String sql = "{call batchUpdateCustomer(?)}";
    CallableStatement cstmt = co***prepareCall(sql);
    cs***.setInt(1, 0);//把年龄参数设置为0;
    cs***.executeUpdate();
   
    //ResultSet rs = cs***.executeQuery(sql);若是查询的时候
    co***commit();
    //***close();
    co***close();
  } catch (SQLException e) {
   e.***ntStackTrace();
  }
}
}

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xixi_666/archive/2009/12/18/5029768.aspx
-

 

上一篇: 性能优化

下一篇: Java虚拟机