hibernate如何获取总记录数? s1是什么东西?hsql的也支持普通的sql的呀,直接select count(*)就好了的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Session s1 = HibernateUtil.currentSession();就是分页的时候希望能先取到表中的记录总数,最好是不用select count(*),不知有没有一个取得总记录数的方法,看了API,好象也没找到。 hsql = "select count(*) from LoveList" return ((Integer)session.createQuery(hsql).iterate().next()).intValue(); 用上边说的方法,没有问题,但是我要说的是对语句可以优化,select count(*) from LoveList改为:select count(id) from LoveList ,这里 id 是主键,当然,要根据你的实际情况写这个字段的名称。 /** * <p> * 对数据库进行操作,返回员工总人数 为分页提供服务 * * @return intcount * */ public int count() throws Exception { log.warn("---->显示员工总人数"); int counts; Session session = BaseHibernate.getSession(); Integer count = (Integer) session.createQuery( "select count(*) from User s").uniqueResult(); counts = count.intValue(); BaseHibernate.closeSession(session); return counts; } 介绍j2ee图书给我 谷歌地图api 如何区分地图是否为放大 菜鸟提个问 jsp页面转向 struts2自动去除首尾空格 100分求韩文乱码问题 如何配置jsp和javabean和servlet服务器(用tomcat5.0或weblogic8)以及在jbuilder9里配置使用 ★★★ 网站开通,600分赠送!(分六次)★★★ win2k下IIS+tomcat(或resin)该怎么配置啊?怎么也搞不定 求消息Bean ---JBuilder7+Weblogic7例子 运行个struts标签的页面竟然这样??? validator使用问题
就是分页的时候希望能先取到表中的记录总数,最好是不用select count(*),不知有没有一个取得总记录数的方法,看了API,好象也没找到。
return ((Integer)session.createQuery(hsql).iterate().next()).intValue();
这里 id 是主键,当然,要根据你的实际情况写这个字段的名称。
* <p>
* 对数据库进行操作,返回员工总人数 为分页提供服务
*
* @return intcount
*
*/ public int count() throws Exception {
log.warn("---->显示员工总人数");
int counts;
Session session = BaseHibernate.getSession();
Integer count = (Integer) session.createQuery(
"select count(*) from User s").uniqueResult();
counts = count.intValue();
BaseHibernate.closeSession(session);
return counts;
}