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会把他认为是调用存储过程