批量执行sql语句

27 篇文章 1 订阅
   protected void _saveByPriceInfo(Context ctx, List list, IObjectValue model)
        throws BOSException, EASBizException
    {
        PriceInfo priceInfo = null;
        if(list != null && list.size() > 0)
        {
            TransferOrderBillInfo billInfo = (TransferOrderBillInfo)model;
            TransferOrderBillEntryInfo entryInfo = null;
            PreparedStatement addStmt = null;
            Connection conn = null;
            Statement stmt = null;
            try
            {
                conn = EJBFactory.getConnection(ctx);
                stmt = conn.createStatement();
                stmt.execute("delete from T_IM_MultiSidesTransferPrices where FTransferBillId = '" + billInfo.getId() + "'");
                StringBuffer sql = new StringBuffer("insert into T_IM_MultiSidesTransferPrices");
                sql.append("(FID,FTransferBillID,FTransferBillEntryID,FSupplyRelationID,FBizRole,FTaxRate");
                sql.append(",FDiscountType,FDiscountRate,FPrice,FActualPrcie,FTaxPrice,FActualTaxPrice)");
                sql.append("values (?,?,?,?,?,?,?,?,?,?,?,?)");
                addStmt = conn.prepareStatement(sql.toString());
                int i = 0;
                int stmtSize = 0;
                for(int size = list.size(); i < size;)
                {
                    priceInfo = (PriceInfo)list.get(i);
                    if(priceInfo != null)
                    {
                        entryInfo = billInfo.getEntry().get(i % billInfo.getEntry().size());
                        if(!entryInfo.isIsPresent() && entryInfo.getSupplyRelation() != null && priceInfo.getBizRoleType() != null)
                        {
                            addStmt.setString(1, BOSUuid.create("31C6DAB6").toString());
                            addStmt.setString(2, billInfo.getId().toString());
                            addStmt.setString(3, entryInfo.getId().toString());
                            addStmt.setString(4, entryInfo.getSupplyRelation().getId().toString());
                            addStmt.setInt(5, priceInfo.getBizRoleType().getValue());
                            addStmt.setBigDecimal(6, entryInfo.getTaxRate());
                            if(priceInfo.getPrice() == null || priceInfo.getPrice().compareTo(zero) <= 0)
                            {
                                addStmt.setInt(7, entryInfo.getDiscountType().getValue());
                                addStmt.setBigDecimal(8, entryInfo.getDiscountRate());
                                addStmt.setBigDecimal(9, entryInfo.getPrice());
                                addStmt.setBigDecimal(10, entryInfo.getActualPrice());
                                addStmt.setBigDecimal(11, entryInfo.getTaxPrice());
                                addStmt.setBigDecimal(12, entryInfo.getActualTaxPrice());
                            } else
                            {
                                addStmt.setInt(7, priceInfo.getDiscountType().getValue());
                                addStmt.setBigDecimal(8, priceInfo.getDiscountRate());
                                addStmt.setBigDecimal(9, priceInfo.getPrice());
                                addStmt.setBigDecimal(10, priceInfo.getActualPrice());
                                addStmt.setBigDecimal(11, priceInfo.getTaxPrice());
                                addStmt.setBigDecimal(12, priceInfo.getActualTaxPrice());
                            }
                            addStmt.addBatch();
                        }
                    }
                    if(stmtSize > 500)
                    {
                        stmtSize = 0;
                        addStmt.executeBatch();
                        addStmt.clearBatch();
                    }
                    i++;
                    stmtSize++;
                }

                addStmt.executeBatch();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
                throw new BOSException(e.getCause());
            }
            finally
            {
                try
                {
                    SQLUtils.cleanup(stmt);
                    SQLUtils.cleanup(addStmt);
                    SQLUtils.cleanup(conn);
                }
                catch(Exception e)
                {
                    throw new BOSException(e.getCause());
                }
            }
        }
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值