hql如何使用count
来源:互联网 发布:java 自行车 编辑:程序博客网 时间:2024/06/11 15:15
//第一种方法:
String hql = "select count(*) from User as user ";
Integer count = (Integer)getHibernateTemplate().find(hql).listIterator().next();
return count.intValue();
//第二种方法:
String hql = "select count(*) from User as user ";
return ((Integer)getHibernateTemplate().iterate(hql).next()).intValue();
//第三种方法:
String hql = "select count(*) from User as user ";
Query query = getHibernateTemplate().createQuery( getSession(),hql);
以上来自:http://blog.sina.com.cn/s/blog_4fb1c0fc0100jepi.html
由于Hibernate版本的问题,(select count(*))查询返回的结果是个Long 不能强制转换:
Long count=0L;
String hql="SELECT COUNT(*) FROM ContentGood cg WHERE cg.id=?";
count=(Long) getSession().createQuery(hql).setString(0, id).iterate().next();
Integer sum = new Integer(String.valueOf(count));
阅读全文
0 0
- hql如何使用count
- Hibernate count如何映射?HQL别名字段问题?
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- HQL中select count(*)与fetch使用出错
- spring + hibernate 如何使用count(*)
- HQL中如何使用Boolean变量
- hql不能在distinct,group by结果集上使用count的问题,报语法错误
- 如何在ContentProvider中使用COUNT()函数
- HQL使用
- 使用hql
- 当HQL中的count遇上distinct/groupby
- HQL count(*) 查询返回的类形
- 当HQL中的count遇上distinct/groupby
- hql 取到 count(*)的值
- 如何在hibernate+mySQL中使用HQL的cast语句
- NIO
- Go语言打印调用堆栈
- 大米互助
- OpenGl的glMatrixMode()函数理解
- think in java 笔记(一) final关键字
- hql如何使用count
- 关于java项目与web项目中lib包的那点事
- 正则表达式
- Windows下python3 连接SQL Server
- JavaWeb 3年工作经验(几个点)
- Spring Cloud vs k8s
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 1039. 到底买不买(20)
- zookeeper 安装 windows环境