复制代码 代码如下:
Usertable user=null;
Session session=HibernateSessionFactory.getSession();
String sql="from Usertable as user where user.username=?";
Query q=session.createQuery(sql);
q.setString(0,username);
List l=q.list();
Iterator ite=l.iterator();
if(ite.hasNext()){
user=(Usertable)ite.next();
}
return user;
复制代码 代码如下:
public boolean updateNews(Devinfo df) throws HibernateException{
net.sf.hibernate.Session sess =HibernateUtil.currentSession();
Transaction tx = sess.beginTransaction();
try{
Devinfo d=new Devinfo();
sess.load(d,df.getNewsid());
d.setTypeId(df.getTypeId());
d.setSubject(df.getSubject());
d.setContent(df.getContent());
d.setMdate(new Date((new java.util.Date()).getTime()).toString());
sess.update(d);
tx.commit();
HibernateUtil.closeSession();
return true;
}
catch(HibernateException e){
e.printStackTrace();
return false;
}
}
新闻热点
疑难解答