hibernate使用hql和sql查询总记录数语句
2014-04-25 14:15
666 查看
hql:
String hql= "select count(*) from table";
try {
Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
i = ((Long) query.iterate().next()).intValue();
}
catch (Exception e) {
// TODO: handle exceptioni= 0;
}
sql:
String sql = "select count(*) from table";
try {
Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sql);
List list = query.list();
i = list.get(0).intValue();
} catch (Exception e) {
// TODO: handle exceptioni= 0;
}
String hql= "select count(*) from table";
try {
Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
i = ((Long) query.iterate().next()).intValue();
}
catch (Exception e) {
// TODO: handle exceptioni= 0;
}
sql:
String sql = "select count(*) from table";
try {
Query query = this.sessionFactory.getCurrentSession().createSQLQuery(sql);
List list = query.list();
i = list.get(0).intValue();
} catch (Exception e) {
// TODO: handle exceptioni= 0;
}
相关文章推荐
- Hibernate查询时,使用HQL和SQL的区别(SUM语句)
- hibernate使用hql和sql查询总记录数和注意事项
- Hibernate 使用纯SQL语句完成查询操作
- Hibernate直接执行sql语句,查询记录的个数
- Hibernate使用sql语句实现多表关联查询
- hibernate如何使用hql语句查询时间区间段
- Hibernate中使用Hql查询出一定时间段的记录
- Hibernate使用sql语句实现多表关联查询
- Hibernate中使用原生的sql语句进行查询操作
- jpa或bernate使用原生sql进行关联查询org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join
- hibernate如何使用hql语句查询时间区间段
- hibernate根据条件动态组装sql/hql语句(仿ibatis动态查询语句功
- 在hibernate中hql语句使用连接查询
- Hibernate使用sql语句查询,返回实体类型的方法及注意事项
- hibernate之HQL语句编写(用于多表查询,单不复杂时使用)
- Hibernate的HQL查询语句对比Sql语句学习
- 使用SQL语句查询每个分组的前N条记录
- 使用SQL语句查询表中重复记录并删除
- 查询出前n条记录的SQL以及Hql语句
- Hibernate使用sql语句查询