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; }
public static CreditCard searchById(int Id) { // Person person = null; Statement stmt = null; CreditCard creditCard = null; String searchQuery = "select * from creditcard where ID ='" + Id + "' "; try { // connect to DB currentCon = DBConnectionManager.getConnection(); stmt = currentCon.createStatement(); rs = stmt.executeQuery(searchQuery); boolean more = rs.next(); // if user does not exist set the isValid variable to false if (!more) { System.out.println("member with the ID = " + Id + " does not exst"); } // if user exists set the isValid variable to true else if (more) { int id = rs.getInt("id"); String cardNumber = rs.getString("cardNumber"); int expiryMonth = rs.getInt("expiryMonth"); int expiryYear = rs.getInt("expiryYear"); String expiryDate = rs.getString("expiryDate"); String cardHolderName = rs.getString("cardHolderName"); String country = rs.getString("country"); int CVC = rs.getInt("CVC"); String streetAddress = rs.getString("streetAddress"); String cardType = rs.getString("cardType"); creditCard = new CreditCard(); creditCard.setId(id); creditCard.setCardNumber(cardNumber); creditCard.setExpiryMonth(expiryMonth); creditCard.setExpiryYear(expiryYear); creditCard.setExpiryDate(expiryDate); creditCard.setCountry(country); creditCard.setCVC(CVC); creditCard.setStreetAddress(streetAddress); creditCard.setCardType(cardType); } } catch (Exception e) { e.printStackTrace(); } finally { 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 creditCard; }
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; }
/** * This method initializes this * * @return void */ private void initialize() { card = CreditCardDAO.searchById(MainFrame.getPersonWhoLogin().getId()); cardNumber = card.getCardNumber() + ""; cardType = card.getCardType(); membership = MainFrame.getPersonWhoLogin().getMembership(); points = MainFrame.getPersonWhoLogin().getPoints(); jLabelCard = new JLabel(); jLabelCard.setText("Card:"); jLabelCard.setPreferredSize(new Dimension(80, 24)); jLabelCard.setBounds(new Rectangle(30, 190, 80, 24)); jLabelCard.setFont(new Font("Arial", Font.BOLD, 18)); jLabelPoints = new JLabel(); jLabelPoints.setFont(new Font("Arial", Font.BOLD, 18)); jLabelPoints.setBounds(new Rectangle(30, 280, 120, 24)); jLabelPoints.setText("Points:"); jLabelMembership = new JLabel(); jLabelMembership.setText("Membership:"); jLabelMembership.setFont(new Font("Arial", Font.BOLD, 18)); jLabelMembership.setBounds(new Rectangle(30, 370, 160, 23)); jLabelMembership.setPreferredSize(new Dimension(200, 29)); jLabelName = new JLabel(); jLabelName.setFont(new Font("Arial", Font.BOLD, 18)); jLabelName.setBounds(new Rectangle(30, 100, 80, 20)); jLabelName.setText("Name:"); jLabelHowMayIServeYou = new JLabel(); jLabelHowMayIServeYou.setText("How May I Serve You?"); jLabelHowMayIServeYou.setFont(new Font("Arial", Font.PLAIN, 18)); jLabelHowMayIServeYou.setFont(new Font("Arial", Font.BOLD, 24)); jLabelHowMayIServeYou.setBounds(new Rectangle(98, 45, 280, 32)); this.setSize(1024, 600); this.setLayout(null); this.setBackground(new Color(227, 228, 250)); this.setFont(new Font("Dialog", Font.PLAIN, 12)); this.add(getJButtonLogout(), null); this.add(getPanel1(), null); this.add(jLabelHowMayIServeYou, null); this.add(jLabelName, null); this.add(jLabelMembership, null); this.add(jLabelPoints, null); this.add(jLabelCard, null); this.add(getJButtonOrchid(), null); this.add(getJButtonGold(), null); this.add(getJButtonSands(), null); this.add(getJButtonDeluxe(), null); this.add(getJButtonPresidential(), null); this.add(getJButtonMembership1(), null); JLabel displayName = new JLabel(""); displayName.setFont(new Font("Calibri", Font.PLAIN, 24)); displayName.setBounds(53, 131, 187, 31); displayName.setText(MainFrame.getPersonWhoLogin().getName()); add(displayName); JLabel displayCard = new JLabel(""); displayCard.setFont(new Font("Calibri", Font.PLAIN, 24)); displayCard.setBounds(53, 225, 235, 31); displayCard.setText( cardType + " XXX-" + cardNumber.charAt(12) + cardNumber.charAt(13) + cardNumber.charAt(14) + cardNumber.charAt(15)); add(displayCard); add(getDisplayPts()); add(displayMembership()); }