public void insertSale(Customer c) throws SQLException { int id = c.getId(); String name = c.getName(); String address = c.getAddress(); String phone = c.getPhoneNumber(); String cardType = c.getCardType(); String cardNumber = c.getCardNumber(); String cardExp = c.getCardExp(); String secCode = c.getSecCode(); String cartDetails = ""; for (Product p : c.getCart().getProductList()) cartDetails += p.getName() + "@" + p.getUnitPrice() + "x" + p.getQuantity() + " "; BigDecimal cartTotal = c.getCart().getTotal().setScale(2); Statement stmt = con.createStatement(); String sql = "INSERT INTO App.SALES VALUES(" + id + ",'" + name + "','" + address + "','" + phone + "','" + cardType + "','" + cardNumber + "','" + cardExp + "','" + secCode + "','" + cartDetails + "'," + cartTotal + ",'" + getCurrentTimeStamp() + "')"; stmt.executeUpdate(sql); }
private static void mainMenu() { System.out.println("\n\nWhat do you want to do?"); System.out.println("1. Search movies by actor"); System.out.println("2. Add a star"); System.out.println("3. Add a customer"); System.out.println("4. Delete a customer"); System.out.println("5. Provide metadata"); System.out.println("6. Run custom SQL query"); System.out.println("7. Logout"); System.out.println("\nPlease make a choice"); choice = inp.nextInt(); switch (choice) { case 1: System.out.println(" Please enter a name: "); String a = inp.nextLine(); searchmovies(a); break; case 2: // Insert a new star to database BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Adding Star..."); System.out.println(" Please enter the id: "); int id1; try { id1 = inp.nextInt(); } catch (InputMismatchException e1) { System.out.println("You did not enter a number!!"); System.out.println("Try again"); id1 = inp.nextInt(); } String[] prompts1 = { "Please enter a first name: ", "Please enter a last name: ", "Please enter a dob: ", "Please enter an photo url: ", }; ArrayList<String> ar1 = new ArrayList<String>(); for (String prompt : prompts1) { System.out.println(prompt); try { ar1.add(br1.readLine()); } catch (IOException e) { System.out.println(e); } } Star star = new Star(id1, ar1.get(0), ar1.get(1), ar1.get(2), ar1.get(3)); try { addstar( star.getId(), star.getFirst_name(), star.getLast_name(), star.getDob(), star.getPhotoURL()); } catch (SQLException e) { System.out.println("Could not add star"); } break; case 3: BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Adding Customer..."); System.out.println(" Please enter the id: "); int id; try { id = inp.nextInt(); } catch (InputMismatchException e1) { System.out.println("You did not enter a number!!"); System.out.println("Try again"); id = inp.nextInt(); } String[] prompts = { "Please enter a first name: ", "Please enter a last name: ", "Please enter a credit card number: ", "Please enter an address: ", "Please enter an email id: ", "Please enter the customer's password: "******"Could not add customer"); } break; case 4: break; case 5: break; case 6: break; case 7: break; default: System.out.println("INVALID OPTION..."); break; } }