Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Customer Inserter: Please refer to The Customer Inserter Problem video located at Case Study section, write an application that connects to the CoffeeDB database, and

Customer Inserter: Please refer to The Customer Inserter Problem video located at Case Study section, write an application that connects to the CoffeeDB database, and allows the user to insert a new row into the Customer table.

Instructions for Submission Upload you InsertCustomer.java, CustomerTableManager.java, and CustomerInfoPanel.java programs.

This is what I have done, but I have a lot of errors. I watched a video of someone doing it so I don't know why I have so many errors. Please help :(

CustomerTableManager.java

import java.sql.*;

public class CustomerTableManager

public List getRelations(Restfulie control) { public final String DB_URL = "jdbc:derby:CoffeeDB";

private Connection conn;

public CustomerTableManager() throws SQLException { conn = DriverManager.getConnection(DB_URL); }

public void insert(String custNum, String name, String address, String city, String state, String zip) throws SQLException

{ String query = "INSERT INTO Customer VALUES" + "(" + "'" + custNum + "' " + "'" + name + "' " + "'" + address + "' " + "'" + city + "' " + "'" + state + "' " + "'" + zip + "'" + ")";

Statement stmt = conn.createStatement();

stmt.executeUpdate(query);

conn.close(); stmt.close();

}

}

--------------------------------------------------------------

InsertCustomer.java

import javax.swing.*; import java.sql.*; import java.awt.*; import java.awt.event.*;

public class InsertCustomer extends JFrame { CustomerInfoPanel customerInfoPanel; JPanel buttonPanel; public InsertCustomer() { setTitle("Add Customer"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); customerInfoPanel = new CustomerInfoPanel(); buildButtonPanel(); setLayout(new BorderLayout()); add(customerInfoPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); pack(); setVisible(true); } private void buildButtonPanel() { buttonPanel = new JPanel(); JButton submitButton = new JButton("Submit"); submitButton.addActionListener(new SubmitButtonListener()); JButton exitButton = new JButton("Exit"); exitButton.addActionListener(new ExitButtonListener()); buttonPanel.add(submitButton); buttonPanel.add(exitButton); } private class SubmitButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { try { String custNum = customerInfoPanel.getCustNum(); String name = customerInfoPanel.getName(); String address = customerInfoPanel.getAddress(); String city = customerInfoPanel.getCity(); String state = customerInfoPanel.getState(); String zip = customerInfoPanel.getZip(); CustomerTableManager ctManager = new CustomerTableManager(); ctManager.insert(custNum, name, address, city, state, zip); customerInfoPanel.clear(); JOptionPane.showMessageDialog(null, "Record Added"); } catch (SQLException ex) { ex.printStackTrace(); System.exit(0); } } } private class ExitButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public static void main(String[] args) { new InsertCustomer(); } }

------------------------------------------------------------------------------------

CustomerInfoPanel.java

import javax.swing.*; import java.awt.*;

public class CustomerInfoPanel extends JPanel { private JTextField custNumTextField; private JTextField nameTextField; private JTextField addressTextField; private JTextField cityTextField; private JTextField stateTextField; private JTextField zipTextField; public CustomerInfoPanel() { JLabel custNumPrompt = new JLabel("Customer Number"); custNumTextField = new JTextField(10); JLabel namePrompt = new JLabel("Name"); nameTextField = new JTextField(25); JLabel addressPrompt = new JLabel("Address"); addressTextField = new JTextField(25); JLabel cityPrompt = new JLabel("City"); cityTextField = new JTextField(12); JLabel statePrompt = new JLabel("State"); stateTextField = new JTextField(2); JLabel zipPrompt = new JLabel("Zip"); zipTextField = new JTextField(5); setLayout(new GridLayout(12, 1)); setBorder(BorderFactory.createTitledBorder("Enter Customer Information")); add(custNumPrompt); add(custNumTextField); add(namePrompt); add(nameTextField); add(addressPrompt); add(addressTextField); add(cityPrompt); add(cityTextField); add(statePrompt); add(stateTextField); add(zipPrompt); add(zipTextField); } public String getCustNum() { return custNumTextField.getText(); } public String getName() { return nameTextField.getText(); } public String getAddress() { return addressTextField.getText(); } public String getCity() { return cityTextField.getText(); } public String getState() { return stateTextField.getText(); } public String getZip() { return zipTextField.getText(); } public void clear() { custNumTextField.setText(""); nameTextField.setText(""); addressTextField.setText(""); cityTextField.setText(""); stateTextField.setText(""); zipTextField.setText(""); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions