コード例 #1
0
  // 更新库存
  public void updateStock(Connection con, ArrayList<SalesReturnDetailOrder> details)
      throws SalesDaoException {
    PreparedStatement ps = null;

    try {
      for (int i = 0; i < details.size(); i++) {
        ps = con.prepareStatement("update tb_stock set amount=amount+? where proId=?");
        // 获取详单信息
        SalesReturnDetailOrder detail = details.get(i);
        // 动态传值
        ps.setInt(1, detail.getAmount());
        ps.setLong(2, detail.getProId());
        // 执行sql
        ps.executeUpdate();
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw new SalesDaoException(e.getMessage());
    } finally {
      // 关闭资源
      try {
        if (ps != null) ps.close();
      } catch (SQLException e) {
        e.printStackTrace();
        throw new SalesDaoException(e.getMessage());
      }
    }
  }
コード例 #2
0
  // 插入销售退货详单记录
  public void insertSalesReturnDetailOrder(
      Connection con, ArrayList<SalesReturnDetailOrder> details) throws SalesDaoException {
    PreparedStatement ps = null;

    try {
      for (int i = 0; i < details.size(); i++) {
        ps = con.prepareStatement("insert into tb_salesReturnDetailOrder values(?,?,?,?)");
        // 获取销售退货详单
        SalesReturnDetailOrder detail = details.get(i);
        // 动态传值
        ps.setString(1, detail.getSalesReturnId());
        ps.setLong(2, detail.getProId());
        ps.setDouble(3, detail.getReturnPrice());
        ps.setInt(4, detail.getAmount());
        // 执行sql
        ps.executeUpdate();
      }

    } catch (SQLException e) {
      e.printStackTrace();
      throw new SalesDaoException(e.getMessage());
    } finally {
      // 关闭资源
      try {
        if (ps != null) ps.close();
      } catch (SQLException e) {
        e.printStackTrace();
        throw new SalesDaoException(e.getMessage());
      }
    }
  }