hibernateTemplate执行存储过程

来源:互联网 发布:流星网络电视直播软件 编辑:程序博客网 时间:2024/05/19 09:03

hibernateTemplate执行存储过程

 
转载

有两种方法可以实现
具体想问一下hibernateTemplate.execute方法有什么作用啊!
collin000.updateDepart是存储过程的名称

 

CallableStatement cstmt = hibernateTemplate.getSessionFactory().getCurrentSession().connection().prepareCall("{call collin000.updateDepart}");

cstmt.executeUpdate();
------------------------------------------------------------------------

第二种
------------------------------------------------------------------------
hibernateTemplate.execute(
 new HibernateCallback()
 {
  public Object doInHibernate(Session session) throws SQLException
  {
   CallableStatement cs = session.connection().prepareCall("{call collin000.updateDepart}");  

   cs.executeUpdate();
   return null;
     }
 }
);
eg:

 CallableStatement cs = this.getHibernateTemplate().getSessionFactory().getCurrentSession().connection()
   .prepareCall("{call pro_Calendar(?,?,?,?,?,?,?)}");
   cs.setString(1, cm.getFdateBegin().toString());
   cs.setString(2, cm.getFdateEnd().toString());
   cs.setInt(3, cm.getFtimes());
   cs.setInt(4, cm.getFinancialMonth());
   cs.setString(5, cm.getFnote());
   cs.setInt(6, cm.getFid());
   cs.setInt(7, cm.getFaddDays());
   
      cs.executeUpdate();

原创粉丝点击