Assignment4_1_Server_POJO/src/ws/customer/service/CustomerService.java
public String writeToDatabase(Customer customer) {
		// Open a connection.
		try (Connection conn = DriverManager.getConnection(CustomerService.url, CustomerService.dbUsername, CustomerService.dbPassword)) {
			// Create preparedStatement obj with specified query.
			String query="INSERT INTO " + tableName + 
					" (customer_id, name, shoppingAmount, privileged, discountPercentage)"
					+ " VALUES (?, ?, ?, ?, ?)";
			PreparedStatement updateCustomer = conn.prepareStatement(query);
			
			// Supply values for preparedStatement param.
			updateCustomer.setInt(1, customer.getCustomerID());
			updateCustomer.setString(2, customer.getCustomerName());
			updateCustomer.setFloat(3, customer.getShoppingAmount());
			updateCustomer.setBoolean(4, customer.getPrivileged());
			updateCustomer.setInt(5, customer.getDiscountPercentage());
			
			// Execute the final query.
			updateCustomer.executeUpdate();
			return "Update successful";
		} catch (SQLException e) {
			return e.getMessage();
		}
	}
/**
	 * write a Customer obj to our database.
	 * @param customer
	 * @return a message informs that the operation was successful, else an exception message.
	 */
write a Customer obj to our database.
@param customer
@return a message informs that the operation was successful, else an exception message.
write a Customer obj to our database . @param customer @return a message informs that the operation was successful else an exception message .
public String writeToDatabase(Customer customer) {
		try (Connection conn = DriverManager.getConnection(CustomerService.url, CustomerService.dbUsername, CustomerService.dbPassword)) {
			String query="INSERT INTO " + tableName + 
					" (customer_id, name, shoppingAmount, privileged, discountPercentage)"
					+ " VALUES (?, ?, ?, ?, ?)";
			PreparedStatement updateCustomer = conn.prepareStatement(query);
			updateCustomer.setInt(1, customer.getCustomerID());
			updateCustomer.setString(2, customer.getCustomerName());
			updateCustomer.setFloat(3, customer.getShoppingAmount());
			updateCustomer.setBoolean(4, customer.getPrivileged());
			updateCustomer.setInt(5, customer.getDiscountPercentage());
			updateCustomer.executeUpdate();
			return "Update successful";
		} catch (SQLException e) {
			return e.getMessage();
		}
	}
public String writeToDatabase ( Customer customer ) { try ( Connection conn = DriverManager . getConnection ( CustomerService . url , CustomerService . dbUsername , CustomerService . dbPassword ) ) { String query = "INSERT INTO " + tableName + " (customer_id, name, shoppingAmount, privileged, discountPercentage)" + " VALUES (?, ?, ?, ?, ?)" ; PreparedStatement updateCustomer = conn . prepareStatement ( query ) ; updateCustomer . setInt ( 1 , customer . getCustomerID ( ) ) ; updateCustomer . setString ( 2 , customer . getCustomerName ( ) ) ; updateCustomer . setFloat ( 3 , customer . getShoppingAmount ( ) ) ; updateCustomer . setBoolean ( 4 , customer . getPrivileged ( ) ) ; updateCustomer . setInt ( 5 , customer . getDiscountPercentage ( ) ) ; updateCustomer . executeUpdate ( ) ; return "Update successful" ; } catch ( SQLException e ) { return e . getMessage ( ) ; } }
write a Customer obj to our database.
write a Customer obj to our database .
// Open a connection. // Create preparedStatement obj with specified query. // Supply values for preparedStatement param. // Execute the final query.