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;
}
//.特别要注意该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;
}
}
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2010/12/20/1911903.html,如需转载请自行联系原作者