hibernate取出count(*)的办法如下:
1、定义查询语句
final String countHql="select count(*) from ExcelInfor";
2、获取count(*)返回结果:
(1)int count=Integer.parseInt(session.createSQLQuery(countHql).list().get(0).toString());
(2)int count=((Long)(session.createQuery(countHql).iterate().next())).intValue();
(3)int count=((Integer)(session.createQuery(countHql).uniqueResult()).intValue();
Query sqlQuery = session.createSQLQuery("select count(*) from tale_name");
List list = sqlQuery.list();
int count = (Integer)list.get(0);
还有一种 直接 getSession().createQuery(sql).uniqueResulet();方法
s手写的,不知道写错没,你看看方法
你查询出来的结果集是List
我明白你的意思了,可以使用别名as _OneName_
select userId,keyWord,count(*) as Count from ActionSearch1 group by userId,keyWord
祝愉快
Query query=session.createQuery(sql);
List list=query.list();
list.size(); 这个就是count(*)咯
看到各位前辈的经验了,可是可是我还是不会,这个问题困扰我两天了,帮帮我吧。我通过hql返回的是一个list,怎么把这个list在jsp中显示啊。多谢谢