Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public int modifyCustomer(Customer customer) {
  2. int result = -1;
  3. try {
  4. PreparedStatement stmt;
  5. if (customer.hasFirstName()) { // Has first name
  6. stmt = con.prepareStatement("UPDATE Customer SET first_name = ? where customer_ID = ?");
  7. stmt.setString(1, customer.getFirstName());
  8. result = stmt.executeUpdate();
  9. }
  10. else if (customer.hasLastName()) { // Has last name
  11. stmt = con.prepareStatement("UPDATE Customer SET last_name = ? where customer_ID = ?");
  12. stmt.setString(1, customer.getLastName());
  13. result = stmt.executeUpdate();
  14. }
  15. else if (customer.hasAddress1()) { // Has address1
  16. stmt = con.prepareStatement("UPDATE Customer SET address1 = ? where customer_ID = ?");
  17. stmt.setString(1, customer.getAddress1());
  18. result = stmt.executeUpdate();
  19. }
  20. else if (customer.hasAddress2()) { // Has address2
  21. stmt = con.prepareStatement("UPDATE Customer SET address2 = ? where customer_ID = ?");
  22. stmt.setString(1, customer.getAddress2());
  23. result = stmt.executeUpdate();
  24. }
  25. else if (customer.hasZone_ID()) { // Has zone_ID
  26. stmt = con.prepareStatement("UPDATE Customer SET zone_ID = ? where customer_ID = ?");
  27. stmt.setInt(1, customer.getZone_ID());
  28. result = stmt.executeUpdate();
  29. }
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. }
  33. return result;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement