Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int modifyCustomer(Customer customer) {
- int result = -1;
- try {
- PreparedStatement stmt;
- if (customer.hasFirstName()) { // Has first name
- stmt = con.prepareStatement("UPDATE Customer SET first_name = ? where customer_ID = ?");
- stmt.setString(1, customer.getFirstName());
- result = stmt.executeUpdate();
- }
- else if (customer.hasLastName()) { // Has last name
- stmt = con.prepareStatement("UPDATE Customer SET last_name = ? where customer_ID = ?");
- stmt.setString(1, customer.getLastName());
- result = stmt.executeUpdate();
- }
- else if (customer.hasAddress1()) { // Has address1
- stmt = con.prepareStatement("UPDATE Customer SET address1 = ? where customer_ID = ?");
- stmt.setString(1, customer.getAddress1());
- result = stmt.executeUpdate();
- }
- else if (customer.hasAddress2()) { // Has address2
- stmt = con.prepareStatement("UPDATE Customer SET address2 = ? where customer_ID = ?");
- stmt.setString(1, customer.getAddress2());
- result = stmt.executeUpdate();
- }
- else if (customer.hasZone_ID()) { // Has zone_ID
- stmt = con.prepareStatement("UPDATE Customer SET zone_ID = ? where customer_ID = ?");
- stmt.setInt(1, customer.getZone_ID());
- result = stmt.executeUpdate();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement