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;
}
本文介绍如何使用HQL和SQL进行表记录数量的查询,并提供了具体的代码实现示例,包括异常处理。
284

被折叠的 条评论
为什么被折叠?



