1. 获取总的记录数
Session session = HibernateUtils.getCurrentSession();
Transaction tr = session.beginTransaction();
List<Number> list = session.createQuery("select count(c) from Customer c").list();
Long count = list.get(0).longValue();
System.out.println(count);
tr.commit();
2. 获取某一列数据的和
Session session = HibernateUtils.getCurrentSession();
Transaction tr = session.beginTransaction();
List<Number> list = session.createQuery("select sum(c.cust_id) from Customer c").list();
Long count = list.get(0).longValue();
System.out.println(count);
tr.commit();
时间: 2024-10-23 03:01:57