Exemple #1
0
  private static String buildInsertQuery(Customer customer) {
    StringBuilder sb = new StringBuilder("INSERT INTO customer_order.customer (ID ");
    StringBuilder valueSb = new StringBuilder("values ( ?");

    if (isValidCriteria(customer.getFirstName())) {
      sb.append(", FIRSTNAME");
      valueSb.append(",?");
    }
    if (isValidCriteria(customer.getLastName())) {
      sb.append(", LASTNAME");
      valueSb.append(",?");
    }
    if (isValidCriteria(customer.getMiddleName())) {
      sb.append(", MIDDLENAME");
      valueSb.append(",?");
    }
    if (isValidCriteria(customer.getNamePrefix())) {
      sb.append(", PREFIX");
      valueSb.append(",?");
    }
    if (isValidCriteria(customer.getGender())) {
      sb.append(", gender");
      valueSb.append(",?");
    }
    valueSb.append(")");
    sb.append(") " + valueSb.toString());

    return sb.toString();
  }
Exemple #2
0
 private static PreparedStatement populateValues(Customer customer, PreparedStatement statement)
     throws SQLException {
   statement.setString(1, customer.getCustomerId());
   // TODO -- dynamic
   int i = 2;
   if (isValidCriteria(customer.getFirstName())) {
     statement.setString(i, customer.getFirstName());
     i++;
   }
   if (isValidCriteria(customer.getLastName())) {
     statement.setString(i, customer.getLastName());
     i++;
   }
   if (isValidCriteria(customer.getMiddleName())) {
     statement.setString(i, customer.getMiddleName());
     i++;
   }
   if (isValidCriteria(customer.getNamePrefix())) {
     statement.setString(i, customer.getNamePrefix());
     i++;
   }
   if (isValidCriteria(customer.getGender())) {
     statement.setString(i, customer.getGender());
     i++;
   }
   return statement;
 }