String hql=”delete from Useradd here addid =10 “;//Useradd为类名.addid为Useradd的属性
//.特别要注意该hql语句中的Useradd不能有别名.
UserDao userdao=new UserDao();
boolean flag=userdao.deletebyJdbcAPI(String hql);

public class UserDao{
      public boolean deletebyJdbcAPI(String hql){
boolean flag=false;
Session session=HibernateSessionFactory.getSession();
Transaction tx=null;
Connection con=null;
PreparedStatement pstn=null;
try{
  tx=session.beginTransaction();
  con=session.connection();
  pstn=con.prepareStatement(hql);
  int i=pstn.executeUdate();
  if(i>0){
   flag=true;
  }
  tx.commit();
}catch(Exception ex){
  if(tx!=null){
   tx.rollback();
  }
}finally{
  session.close();
}
return flag;
     }
}

版权声明:本文为soundcode原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/soundcode/archive/2010/12/20/1911903.html