hibernate使用hql和sql查询总记录数语句

来源:互联网 发布:主宰西游灵宠进阶数据 编辑:程序博客网 时间:2024/05/18 01:05

hql:

 String hql= "select count(*) from table"; 

try {

Query query = this.sessionFactory.getCurrentSession().createQuery(hql);

i = ((Long) query.iterate().next()).intValue();

catch (Exception e) {

// TODO: handle exceptioni= 0;


sql: 

String sql = "select count(*) from table";

 try {

Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sql);

 List list = query.list(); 

i = list.get(0).intValue();

} catch (Exception e) {

// TODO: handle exceptioni= 0;

}

0 0