`
风沙星辰
  • 浏览: 56393 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

hibernate完成oracle存储过程(stored procedures)

    博客分类:
  • java
阅读更多
import java.sql.CallableStatement;
import java.sql.Connection;
import org.apache.log4j.Logger;
import org.hibernate.classic.Session;

import com.check.base.BaseHibernate;
import com.check.collection.dao.CollectionDao;

public class CollectionHibernate extends BaseHibernate implements CollectionDao {
private Logger logger = Logger.getLogger(CollectionHibernate.class);
/* 采集OBDATA
*/
public boolean getOBData(String oldtime,String citytype, String cityType, String deptmentIds) throws Exception {
   // TODO 采集

logger.info("CollectionHibernate getOBData is Begin...");
   boolean bool = false;
   CallableStatement stmt = null;
   Connection conn = null;
   Session session = null;
   try{
    session = this.getHibernateTemplate().getSessionFactory().openSession();
    conn = session.connection();
    stmt = conn.prepareCall("{call Proc_GETLINKDATA(?,?)}");
    stmt.setString(1,oldtime);
    stmt.setString(2,citytype);
    stmt.execute();
   
    if (deptmentIds.length() > 0) {
     stmt = conn.prepareCall("{call DATADELETEBYDATEANDDEPT(?, ?, ?)}");
     stmt.setString(1, "");
     stmt.setString(2, deptmentIds);
     stmt.setString(3, cityType);
     stmt.execute();
    }
   
    conn.commit();
    bool = true;
   }catch(Exception e){
    e.printStackTrace();
    conn.rollback();
   }finally{
    if (session != null) {
     session.close();
    }
   }
   logger.info("CollectionHibernate getOBData is End...");
   return bool;
}

}


特别注意的是调用普通HQL语句的时候HQL里面不能有call关键字,以为hibernate会把他认为是调用存储过程
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics