Hibernate 如何使用count(*)
来源:互联网 发布:聂子佩 知乎回国 编辑:程序博客网 时间:2024/05/27 00:56
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();
}
}
Strings + 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();
================================================================
================================================================
又一种bt的方法!呵呵!
String result = query.uniqueResult().toString();
return Integer.parseInt(result);
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- Hibernate 如何使用count(*)
- spring + hibernate 如何使用count(*)
- Hibernate中如何使用count(*)取得表中记录总数
- Hibernate中如何使用count(*)取得表中记录总数
- Hibernate中如何使用count(*)取得表中记录总数
- hql如何使用count
- Hibernate 使用 count(*)、avg、sum
- Hibernate中使用COUNT DISTINCT
- hibernate 中的count和distinct同时使用
- Hibernate中使用count(*)统计记录总数
- Hibernate使用count(*)得到数据总数
- hibernate count
- Hibernate count如何映射?HQL别名字段问题?
- 如何在ContentProvider中使用COUNT()函数
- //使用hibernate,实现group by and sum and count
- Oracle 9i 、Oracle 10g 和 Oracle 11g 的区别
- 仙台
- Bibliography Entry Types for .bib file
- 学宇 讲三层 收获
- Android 2.1 中 JNI 层 camera 的应用
- Hibernate 如何使用count(*)
- 堆和栈的区别(转过无数次的文章)
- C/C++中单井号与双井号的使用
- 小小感叹
- Python二三事 - 接触Python(x,y)
- SNS游戏开发的技术准备
- js实现的非跨域的iframe高度自适应(完美兼容IE,FF,Opera)
- 左侧悬浮菜单实例代码
- wathdog