HQL的增删改查操作

Posted on 2011-11-22 09:24 陈小东 阅读(783) 评论(0)  编辑  收藏
实体更新
Transaction trans=session.beginTransaction();   
String hql=”update User user set user.age=20 where user.age=18”;   
Query queryupdate=session.createQuery(hql);   
int ret=queryupdate.executeUpdate();   
trans.commit();
实体删除
Transaction trans=session.beginTransaction();   
String hql=”delete from User user where user.age=18”;   
Query queryupdate=session.createQuery(hql);   
int ret=queryupdate.executeUpdate();   
trans.commit();
属性查询
List list=session.createQuery(“select user.name from User user ”).list();   
for(int i=0){   System.out.println(list.get(i));   }

一次检索多个属性,如下面程序:   
List list=session.createQuery(“select user.name,user.age from User user ”).list();   for(int i=0;i<list.length();i++){   Object[] obj=(Object[])list.get(i);   System.out.println(obj[0]);   System.out.println(obj[1]);   }

只有注册用户登录后才能发表评论。


网站导航:
 

posts - 34, comments - 38, trackbacks - 0, articles - 0

Copyright © 陈小东