日期:2014-05-19 浏览次数:20638 次
public static void executeUpdate(String hql,String[] parameters){
Session s=null;
Transaction ts=null;
try {
s=openSession();
ts=s.beginTransaction();
Query query=s.createQuery(hql);
if(parameters!=null && parameters.length>0){
for(int i=0;i<parameters.length;i++){
query.setString(i,parameters[i] );
}
}
query.executeUpdate();
ts.commit();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally{
if(s!=null && s.isOpen()){
s.close();
}
}
}