Esempio n. 1
0
  public void insertCustomers(List<Customer> customers) throws Exception {
    Connection conn = null;
    PreparedStatement prep = null;
    try {
      init();
      conn = getConnection();
      conn.setAutoCommit(false);
      for (Customer customer : customers) {

        prep =
            conn.prepareStatement(
                "insert into customer values ( null,"
                    + "?,"
                    + "?,"
                    + "?,"
                    + " ?,"
                    + "?,"
                    + " ?,"
                    + "?,"
                    + "? ,"
                    + "? ,"
                    + "?,"
                    + "?,"
                    + "?,"
                    + "? , ?, ?);");

        prep.setInt(1, customer.getSerialNumber());
        prep.setString(2, customer.getSeries());
        prep.setString(3, customer.getTicketNumber());
        prep.setString(4, customer.getName());
        prep.setString(5, customer.getLotteryType());
        prep.setString(6, customer.getBumperName());
        prep.setString(7, customer.getPhoneNumber());
        prep.setString(8, customer.getEmailId());
        prep.setString(9, customer.getAddress());
        prep.setBoolean(10, false);
        prep.setBoolean(11, false);
        prep.setString(12, Constants.backupMessage);
        prep.setString(13, Util.formatDate(customer.getDate()));
        prep.setString(14, Util.formatDate(new Date()));
        prep.setString(15, Util.formatDate(new Date()));
        prep.addBatch();

        prep.executeBatch();

        prep.close();
      }
      conn.commit();

    } catch (Exception e) {
      LotteryLogger.getInstance().setError("Error in inserting customers," + e.getMessage());
      if (conn != null) conn.rollback();
      throw new Exception("Error in inserting customer," + e.getMessage());

    } finally {
      if (prep != null) prep.close();
      if (conn != null) conn.close();
    }
  }
Esempio n. 2
0
  public void savePendings(
      List<Customer> customers, boolean isMessageSend, boolean isMailSend, String status)
      throws Exception {
    Connection conn = null;
    PreparedStatement prest = null;

    try {
      init();

      conn = getConnection();
      conn.setAutoCommit(false);

      for (Customer customer : customers) {
        String sql = "delete from customer where serialNumber=" + customer.getSerialNumber();

        Statement stat = conn.createStatement();
        stat.execute(sql);
        PreparedStatement prep =
            conn.prepareStatement(
                "insert  into customer values ( null,"
                    + "?,"
                    + "?,"
                    + "?,"
                    + " ?,"
                    + "?,"
                    + " ?,"
                    + "?,"
                    + "? ,"
                    + "? ,"
                    + "?,"
                    + "?,"
                    + "?,"
                    + "? , ?, ?,?) ;");

        prep.setInt(1, customer.getSerialNumber());
        prep.setString(2, customer.getSeries());
        prep.setString(3, customer.getTicketNumber());
        prep.setString(4, customer.getName());
        prep.setString(5, customer.getLotteryType());
        prep.setString(6, customer.getBumperName());
        prep.setString(7, customer.getPhoneNumber());
        prep.setString(8, customer.getEmailId());
        prep.setString(9, customer.getAddress());
        prep.setBoolean(10, isMessageSend);
        prep.setBoolean(11, isMailSend);
        prep.setString(12, status);
        prep.setString(13, Util.formatDate(customer.getDate()));
        prep.setString(14, Util.formatDate(new Date()));
        prep.setString(15, Util.formatDate(new Date()));
        prep.addBatch();

        prep.executeBatch();

        prep.close();
      }
      conn.commit();

    } catch (Exception e) {
      LotteryLogger.getInstance().setError("Error in inserting pending customers" + e.getMessage());
      if (conn != null) conn.rollback();
      throw new Exception("Error in inserting pending customers");

    } finally {
      if (conn != null) conn.close();
    }
  }