• 注意资源利用 不然导致资源消耗会很严重


    for(Shop s:list) {
                System.out.println(s.getName());
                String sql="select shopId,sum(ele_bank+ele_card+water_card+water_bank+coal_card+coal_bank) as zonghe ,sum(sale_bank+sale_card) as  sale,sum(cigarette_card+cigarette_bank)  as bacco, sum(yidong_card+yidong_bank+dianxin_card+dianxin_bank)  as recharge from hs_shop_items  where  record_time like '%2013-12-12%' and shopId="+s.getId();
                Session officeSession=officeSessionFactory.openSession();
                officeSession.beginTransaction();
                SQLQuery queryOffice=officeSession.createSQLQuery(sql);
                List<ShopTransDTO>  r=queryOffice.addEntity(ShopTransDTO.class).list();
                res.add(r.get(0));
            }
    

      

    如上图中的

    Session officeSession=officeSessionFactory.openSession();
    officeSession.beginTransaction();
    

      

    这个部分放在循环中是错误的

    应该这么写:

    Session officeSession=officeSessionFactory.openSession();
    officeSession.beginTransaction();
    for(Shop s:list) {
                System.out.println(s.getName());
                String sql="select shopId,sum(ele_bank+ele_card+water_card+water_bank+coal_card+coal_bank) as zonghe ,sum(sale_bank+sale_card) as  sale,sum(cigarette_card+cigarette_bank)  as bacco, sum(yidong_card+yidong_bank+dianxin_card+dianxin_bank)  as recharge from hs_shop_items  where  record_time like '%2013-12-12%' and shopId="+s.getId();
                SQLQuery queryOffice=officeSession.createSQLQuery(sql);
                List<ShopTransDTO>  r=queryOffice.addEntity(ShopTransDTO.class).list();
                res.add(r.get(0));
    }
    

      

  • 相关阅读:
    mysql导入导出sql文件
    linux 监控文件变化
    LeetCode:595.大的国家
    LeetCode:176.第二高的薪水
    LeetCode:182.查找重复的电子邮箱
    Excel学习笔记:行列转换
    通过数据分析题目实操窗口函数
    Oracle学习笔记:窗口函数
    Python学习笔记:利用爬虫自动保存图片
    电商数据分析基础指标体系(8类)
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/5537195.html
Copyright © 2020-2023  润新知