Hibernate批量数据操作
/*Hibernate批量数据操作*/
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;
import java.util.List;
class
{
public static void main(String[] args)
{
Session session=util.HibernateSessionFactory.getSession();
/*1、查询所有数据*/
String hql="from Customer where Cbalance>1000";
Query query=session.createQuery(hql);
List list=query.list();
for(int i=0;i<list.size();i++)
{
Customer cus=(Customer)list.get(i);
System.out.println(cus.getCaccount());
System.out.println(cus.getPassword());
System.out.println(cus.getCbalance());
System.out.println(cus.getUsername());
}
/*2、查询指定数据*/
double money=1000;
String hql="Select account , Cbalance from Customer where Cbalance>:money";
Query query=session.createQuery(hql);
query.setDouble("money",money);
List list=query.list();
for(int i=0;i<list.size();i++)
{
Object[] obj=(Object[])list.get(i);
System.out.println(Obj[0]);
System.out.println(Obj[1]);
}
util.HibernateSessionFactory.closeSession();
}
}