hibernate 怎么取出COUNT(*)

2025年03月13日 06:42
有6个网友回答
网友(1):

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();

网友(2):

Query sqlQuery = session.createSQLQuery("select count(*) from tale_name");
List list = sqlQuery.list();
int count = (Integer)list.get(0);

还有一种 直接 getSession().createQuery(sql).uniqueResulet();方法

s手写的,不知道写错没,你看看方法

网友(3):

你查询出来的结果集是List类型的.
取数据,如第一条数据: Object o[]=(Object [])list.get(0);
o[0]为userId,
o[1]为keyWord,
o[2]为count(*)的数据.

网友(4):

我明白你的意思了,可以使用别名as _OneName_

select userId,keyWord,count(*) as Count from ActionSearch1 group by userId,keyWord

祝愉快

网友(5):

Query query=session.createQuery(sql);
List list=query.list();
list.size(); 这个就是count(*)咯

网友(6):

看到各位前辈的经验了,可是可是我还是不会,这个问题困扰我两天了,帮帮我吧。我通过hql返回的是一个list,怎么把这个list在jsp中显示啊。多谢谢