Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Manage customer data (GUI) Operation This application begins by displaying a tab

ID: 3580193 • Letter: M

Question

Manage customer data (GUI)

Operation

This application begins by displaying a table of customer data.

If the user clicks the Add button, the application allows the user to add customer data to the table (and the underlying database).

If the user selects a customer row and clicks the Edit button, the application allows the user to update the data for the selected customer row in the table (and the database).

If the user selects a customer row and clicks the Delete button, the application deletes the selected customer row from the table (and the database).

Specifications

Create a table in the mma database described in chapter 19 to store the necessary data. To do that, you can use the SQL script stored in the create_customer_table.sql file that’s supplied. If this script isn’t supplied, you can create your own SQL script.

Create a class named Customer that stores data for the user’s id, email address, first name, and last name.

Create a class named CustomerDB that contains the methods necessary to get an array list of Customer objects, to get a Customer object for the customer with the specified id, and to add, update, or delete the specified customer.

Create a CustomerManagerFrame class like the one shown above. This frame should display a table of customer data as well as the Add, Edit, and Delete buttons. This class should use the Customer and CustomerDB classes to work with the customer data.

Create a CustomerForm class that allows the user to add or edit customer data.

Create a Java Customer Management program with NetBeans that satisfies the specifications above.

Customer Manager Email frankiones nes@yahoo.com johnsmith@hotmail.com seagreen@levi.com wendyk@warners.com First Name Last Name Frank Jones John Smith Green Cynthia Wendy Kowolski Add Eidt Delete

Explanation / Answer

CREATE TABLE Customer (
CustomerID int,
Emailid varchar(255),
LastName varchar(255),
FirstName varchar(255)
);

public class Customer {

private String id;
private String firstName;
private String lastName;
private String email;

public Customer(String id, String firstName, String lastName,
String email) {
setId(id);
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
}

public void print() {
System.out.printf("%s First Name: %s Last Name: %s Email: {%d, %d, %d} ",
getId(), getFirstName(), getLastName(), getEmail());
}

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class CustomerManagerFrame {

public static Connection createConnection()
{

String url = null;
Connection connection = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
url = "jdbc:mysql://HOST/DATABASE";
connection = DriverManager.getConnection(url, "username", "password");
} catch (Exception e1) {
e1.printStackTrace();
}

return connection;
}

public static List<Customer> getCustomersList(){
List<Customer> customers= new ArrayList<Customer>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSet set = null;

try {
conn = createConnection();
stmt = conn.prepareStatement("SELECT * FROM Customer");
stmt.execute();
set = stmt.getResultSet();

while(set.next()) {
Customer cus= new Customer(set.getString("CustomerID"),set.getString("Emailid"),set.getString("LastName"),set.getString("FirstName"));
customers.add(cus);
}

set.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

return customers;
}

private static Customer getRequiredCustomer(String customerID)
{
Customer customer= null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet set = null;

try {
conn = createConnection();
stmt = conn.prepareStatement("SELECT * FROM Customer where CustomerID="+customerID);
stmt.execute();
set = stmt.getResultSet();

while(set.next()) {
customer = new Customer(set.getString("CustomerID"),set.getString("Emailid"),set.getString("LastName"),set.getString("FirstName"));

}

set.close();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

return customer;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote