コード例 #1
0
  public Customer getCustomer(String customerID) {
    try {
      global.openDBconnection();

      int customer_id = Integer.parseInt(customerID);

      global.select_customer_where_status_customer_id.setBoolean(1, true);
      global.select_customer_where_status_customer_id.setInt(2, customer_id);
      ResultSet rs = global.select_customer_where_status_customer_id.executeQuery();
      if (rs.next()) {
        Customer customer = new Customer();
        customer.set_customer(
            rs.getInt("id"),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));
        customer.setUsername(rs.getString("username"));

        return customer;
      }

      return new Customer();
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return new Customer();
    } finally {
      global.closeDBconnection();
    }
  }
コード例 #2
0
  public List<Customer> getAllCustomers() {
    try {
      global.openDBconnection();

      List<Customer> customers = new ArrayList<Customer>();

      global.select_customer_where_status.setBoolean(1, true);
      ResultSet rs = global.select_customer_where_status.executeQuery();
      while (rs.next()) {
        Customer customer = new Customer();
        customer.set_customer(
            rs.getInt("id"),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));
        customer.setUsername(rs.getString("username"));

        customers.add(customer);
      }

      return customers;
    } catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      return new ArrayList<Customer>();
    }
  }
コード例 #3
0
  public Customer get_customer() {
    try {
      global.openDBconnection();

      Customer customer = new Customer();
      int membership_id = 0;

      // set from user table
      customer.set_user(data.getUser_id(), data.getUsername());

      // set from customer table
      global.select_customer_where_id.setInt(1, data.getCustomer_id());
      ResultSet rs = global.select_customer_where_id.executeQuery();
      if (rs.next()) {
        customer.set_customer(
            data.getCustomer_id(),
            rs.getString("email"),
            new Date(rs.getTimestamp("registered").getTime()),
            rs.getBoolean("status"),
            rs.getString("phonenumber"),
            rs.getString("license_firstname"),
            rs.getString("license_middlename"),
            rs.getString("license_lastname"),
            rs.getDate("license_birthdate"),
            rs.getDate("license_expiration"),
            rs.getString("license_state"),
            rs.getString("license_no"),
            new Date(rs.getTimestamp("membership_exp").getTime()),
            rs.getDouble("balance"));

        membership_id = rs.getInt("membership_id");
      }

      // set from customer address table
      global.select_customer_address_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_address_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_address(
            rs.getInt("id"),
            rs.getString("name"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer creditcard table
      global.select_customer_creditcard_where_customer_id.setInt(1, data.getCustomer_id());
      rs = global.select_customer_creditcard_where_customer_id.executeQuery();
      if (rs.next()) {
        customer.set_customer_creditcard(
            rs.getInt("id"),
            rs.getString("no"),
            rs.getString("code"),
            rs.getDate("expires"),
            rs.getString("firstname"),
            rs.getString("lastname"),
            rs.getString("street1"),
            rs.getString("street2"),
            rs.getString("city"),
            rs.getString("state"),
            rs.getString("zip"));
      }

      // set from customer table
      if (membership_id == 0) {
        customer.set_membership(membership_id, "Free", "", 0.0, 0);
      } else {
        global.select_membership_where_id.setInt(1, membership_id);
        rs = global.select_membership_where_id.executeQuery();
        if (rs.next()) {
          customer.set_membership(
              membership_id,
              rs.getString("name"),
              rs.getString("description"),
              rs.getDouble("price"),
              rs.getInt("months"));
        }
      }

      return customer;
    } catch (Exception e) {
      System.err.println(e.getMessage());
      return new Customer();
    } finally {
      global.closeDBconnection();
    }
  }