zoukankan      html  css  js  c++  java
  • dljd_051_hibernate_单表查询-聚合函数查询

    一、聚合函数之查询学生表中的总记录数

      

    package edu.aeon.hibernate.test;
    
    
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.junit.Test;
    
    import edu.aeon.aeonutils.hibernate.getsessionutil.GetSessionUtil;
    /**    
     * [说明]:查询学生表中的总记录数
     * @author aeon
     *
     */
    public class TestQuery {
        @Test
        public  void testQueryRecordCount() {
            Session session=null;
            Transaction transaction=null;
            try {
                session = GetSessionUtil.getSession();
                transaction=session.getTransaction();
                transaction.begin();
                //这里的count(*)相当于count(id)
                String sql = "select count(*) from Student";
                long count=(long) session.createQuery(sql).uniqueResult();
                System.out.println("总记录数为:"+count);
                session.getTransaction().commit();
            } catch (Exception e) {
                e.printStackTrace();
                //事物的回滚操作
                transaction.rollback();
            }
        }
    }

    数据库数据截图:

      

    执行结果截图:

      

    如有任何疑问可联系邮箱: 给我发邮件、或直接联系QQ:1584875179 || 点返回首页

  • 相关阅读:
    阿里巴巴的字体图标库不错
    SQL语句一次INSERT多条记录的方法
    Oracle中改变表的Owner和tablespace
    QQ在线状态的使用
    gtest
    Git
    gRPC安装的小问题
    蓝桥杯试题 基础练习 查找整数
    Product Backlog
    本周工作量统计
  • 原文地址:https://www.cnblogs.com/aeon/p/10106533.html
Copyright © 2011-2022 走看看