Hibernate批处理

/*Transaction tran = session.beginTransaction();
        Connection connection = session.connection();
        String sql = "INSERT INTO DomainBandwidth(domain_id,traffic,time) VALUES(?,?,?)";
        PreparedStatement ps = null;
        try {
            ps = connection.prepareStatement(sql);
            for (SnFlowDetailResult snFlowDetailResult : snFlowDetailResults){
                boolean flag = false;
                if (flag){

                }else{
                    ps.setInt(1, domainId);
                    ps.setDouble(2, snFlowDetailResult.getTraffic());
                    ps.setTimestamp(3, new Timestamp(snFlowDetailResult.getTime()));
                    ps.addBatch();//添加到批次
                }
            }
            ps.executeBatch();
            tran.commit();
        } catch (Exception e) {
            tran.rollback();
            log.error("", e);
        }finally {
            try {
                ps.close();
                connection.close();
                session.close();
            } catch (Exception e) {
                log.error("", e);
            }
        }*/
//sql语句
//        String updateSql = "UPDATE DomainBandwidth SET traffic = ? WHERE domain_id = ? and time = ?";
        //通过session获取事务 和spring整合之后这步并不需要
//        Transaction ts = session.beginTransaction();
        /*session.doWork(
                //实现work接口,work接口中有一个execute方法,connection就是这个方法的参数,也就是在这里获得jdbc的connection
                new Work(){
                    @Override
                    public void execute(java.sql.Connection connection) throws SQLException {
                        try {
                            connection = session.connection();
                            PreparedStatement stmt = connection.prepareStatement(updateSql);
                            //这里进行批量操作
                            for (SnFlowDetailResult snFlowDetailResult : snFlowDetailResults){
                                stmt.setDouble(1, snFlowDetailResult.getTraffic());
                                stmt.setInt(2, domainId);
                                stmt.setTimestamp(3, new Timestamp(snFlowDetailResult.getTime()));
                                stmt.addBatch(); // 添加到批处理命令
                            }
                            stmt.executeBatch();
                            ts.commit();
                        } catch (Exception e) {
                            e.printStackTrace();
                            ts.rollback();
                            session.close();
                        }
                    }
                });
        session.close();*/

当当
https://blog.csdn.net/jinjiankang/article/details/78846518
https://gelei1014.iteye.com/blog/2095976
https://blog.csdn.net/zjt1388/article/details/52411901
http://www.imooc.com/article/277638
https://blog.csdn.net/yehuang_0801/article/details/78731122
https://www.cnblogs.com/codestory/p/5591651.html
https://blog.csdn.net/myshy025tiankong/article/details/83096720
http://www.manongjc.com/article/4243.html
https://blog.csdn.net/weixin_41704829/article/details/83023543

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值