Beispiel #1
0
  public static boolean updateCreditCard(CreditCard cc, int ID) throws SQLException {
    String cardNumber = cc.getCardNumber();
    int expiryMonth = cc.getExpiryMonth();
    int expiryYear = cc.getExpiryYear();
    String expiryDate = cc.getExpiryDate();
    String cardHolderName = cc.getCardHolderName();
    String country = cc.getCountry();
    int CVC = cc.getCVC();
    String streetAddress = cc.getStreetAddress();
    String cardType = cc.getCardType();
    boolean success = false;
    DBController db = new DBController();
    String dbQuery =
        "UPDATE creditcard set CardNumber = '"
            + cardNumber
            + "',"
            + "ExpiryMonth='"
            + expiryMonth
            + "',ExpiryYear='"
            + expiryYear
            + "',"
            + "ExpiryDate='"
            + expiryDate
            + "',CardHolderName='"
            + cardHolderName
            + "',"
            + "Country='"
            + country
            + "',CVC='"
            + CVC
            + "',StreetAddress='"
            + streetAddress
            + "',"
            + "cardType='"
            + cardType
            + "'WHERE ID = '"
            + ID
            + "'";
    db.getConnection();

    if (db.updateRequest(dbQuery) == 1) {
      success = true;
    }
    db.terminate();
    return success;
  }
Beispiel #2
0
  public static boolean createCreditCard(CreditCard cc) throws SQLException {
    int id = 0;
    Statement stmt = null;
    Connection con = null;
    con =
        DriverManager.getConnection(
            "jdbc:mysql://localhost:8888/simplytech", "simplyTECH", "hahaudie");
    stmt = con.createStatement();
    String query = "SELECT MAX(ID) FROM person";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
      id = rs.getInt("MAX(ID)");
    }
    String cardNumber = cc.getCardNumber();
    int expiryMonth = cc.getExpiryMonth();
    int expiryYear = cc.getExpiryYear();
    String expiryDate = cc.getExpiryDate();
    String cardHolderName = cc.getCardHolderName();
    String country = cc.getCountry();
    int CVC = cc.getCVC();
    String streetAddress = cc.getStreetAddress();
    String cardType = cc.getCardType();

    boolean success = false;
    DBController db = new DBController();

    String dbQuery =
        "INSERT INTO creditcard (ID,CardNumber,ExpiryMonth,ExpiryYear,ExpiryDate,CardHolderName,Country,"
            + "CVC,StreetAddress,CardType) VALUES ('"
            + id
            + "','"
            + cardNumber
            + "','"
            + expiryMonth
            + "','"
            + expiryYear
            + "','"
            + expiryDate
            + "','"
            + cardHolderName
            + "','"
            + country
            + "','"
            + CVC
            + "','"
            + streetAddress
            + "','"
            + cardType
            + "')";
    if (db.updateRequest(dbQuery) == 1) {
      success = true;
    }
    if (rs != null) {
      try {
        rs.close();
      } catch (Exception e) {
      }
      rs = null;
    }

    if (stmt != null) {
      try {
        stmt.close();
      } catch (Exception e) {
      }
      stmt = null;
    }

    if (currentCon != null) {
      try {
        currentCon.close();
      } catch (Exception e) {
      }

      currentCon = null;
    }
    return success;
  }