Hibernate中如何使用count(*)取得表中记录总数
来源:互联网 发布:ubuntu查看内核版本 编辑:程序博客网 时间:2024/06/01 08:24
public int getCount(String emailGroupId, String emailBatchId)
throws HibernateException {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
String hql = "select count(*) from EmailSendInfo where email_group_id = :emailGroupId and batch_id = :batchId";
Query query = session.createQuery(hql);
query.setString("emailGroupId", emailGroupId);
query.setString("batchId", emailBatchId);
/**//*
* for (Iterator it = query.iterate(); it.hasNext();) { return
* ((Integer) it.next()).intValue(); }
*/
try {
return ((Integer) query.iterate().next()).intValue();
} catch (Exception e) {
throw new HibernateException("");
} finally {
tx.commit();
HibernateUtil.closeSession();
}
}
spring+hibernate
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);
return ((Integer)query.uniqueResult()).intValue();
- Hibernate中如何使用count(*)取得表中记录总数
- Hibernate中如何使用count(*)取得表中记录总数
- Hibernate中如何使用count(*)取得表中记录总数
- Hibernate使用count(*)取得表中记录总数
- Hibernate使用count(*)取得表中记录总数
- Hibernate使用count(*)取得表中记录总数
- Hibernate使用count(*)取得表中记录总数
- Hibernate使用count(*)取得表中记录总数(跨Hibernate3.x版本问题)(转)
- Hibernate中使用count(*)统计记录总数
- MS SQLSERVER中如何快速获取表的记录总数
- MS SQLSERVER中如何快速获取表的记录总数
- MS SQLSERVER中如何快速获取表的记录总数
- MSSQLSERVER中如何快速获取表的记录总数
- MS SQLSERVER中如何快速获取表的记录总数
- MS SQLSERVER中如何快速获取表的记录总数
- Hibernate使用count(*)得到数据总数
- Hibernate中使用COUNT DISTINCT
- hibernate中HQL查询count返回query取得其长度
- VC编写DLL几种方法的简介
- CentOS 5.3 内核编译
- 劳动法主体a
- [法学本科]《劳动法》复习资料 问答题 1
- 荐] java数据库设计中的14个技巧[问题点数:100分]
- Hibernate中如何使用count(*)取得表中记录总数
- 初学hibernate笔记
- 初学hibernate总结
- javascript中的readOnly
- 探索lighttpd用fastcgi模式访问django
- [C#] setup factory 教程
- [SVN]SVN初使用笔记
- 六十星系之08太阳天梁坐卯酉
- 度过有意义的生命--俞敏洪2009-06-02同济大学的演讲