Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.sql.*;
- import java.awt.event.*;
- public class CycleBusinessGUI extends JFrame implements ActionListener {
- //Employee
- JLabel ID = new JLabel("Employee ID");
- JTextField jtfID = new JTextField(20);
- JLabel firstName = new JLabel("First Name");
- JLabel lastName = new JLabel("Last Name");
- JLabel expertise = new JLabel("Expertise");
- JLabel yearHired = new JLabel("Year Hired");
- JLabel supervisor = new JLabel("Supervisor");
- JLabel phone = new JLabel("Phone Number");
- JLabel email = new JLabel("Email Address");
- JLabel relation = new JLabel("Relationship Status");
- JTextField firstN = new JTextField(20);
- JTextField lastN = new JTextField(20);
- JTextField exper = new JTextField(20);
- JTextField yearH = new JTextField(20);
- JTextField superV = new JTextField(20);
- JTextField phoneN = new JTextField(20);
- JTextField emailA = new JTextField(20);
- JTextField relaS = new JTextField(20);
- JTextArea descript = new JTextArea(5,40);
- JTextArea descript2 = new JTextArea(5,40);
- JScrollPane jspDescript = new JScrollPane(descript);
- JScrollPane jspDescript2 = new JScrollPane(descript2);
- JButton find = new JButton("Find");
- JButton add = new JButton("Add");
- JButton update = new JButton("Update");
- JButton clear = new JButton("Clear");
- JButton delete = new JButton("Delete");
- JButton audit = new JButton("Audit");
- //Customer
- JTextField creditR = new JTextField(20);
- JTextField addressN = new JTextField(20);
- JTextField cityW = new JTextField(20);
- JTextField stateW = new JTextField(20);
- JTextField zipC = new JTextField(20);
- JTextField n = new JTextField(20);
- JTextField cPhoneN = new JTextField(20);
- JTextField cusIDI = new JTextField(20);
- JTextArea cusArea = new JTextArea(5,40);
- JTextArea cusArea2 = new JTextArea(5,40);
- JButton cFind = new JButton("Find");
- JButton cAdd = new JButton("Add");
- JButton cUpdate = new JButton("Update");
- JButton cClear = new JButton("Clear");
- JButton cDelete = new JButton("Delete");
- JButton cAudit = new JButton("Audit");
- JLabel creditRating = new JLabel("Credit Rating");
- JLabel address = new JLabel("Address");
- JLabel city = new JLabel("City");
- JLabel state = new JLabel("State");
- JLabel zip = new JLabel("Zip Code");
- JLabel name = new JLabel("Name");
- JLabel cPhone = new JLabel("Phone");
- JLabel cusID = new JLabel("Customer ID");
- JTabbedPane jtpComplete = new JTabbedPane();
- //MotoCycle
- JLabel motoID = new JLabel("Moto ID");
- JLabel info = new JLabel("Description");
- JLabel manu = new JLabel("Manufacturer");
- JLabel msrp = new JLabel("MSRP");
- JLabel cate = new JLabel("Category");
- JTextField jtfmoto = new JTextField(20);
- JTextField jtfInfo = new JTextField(20);
- JTextField jtfManu = new JTextField(20);
- JTextField jtfMsrp = new JTextField(20);
- JTextField jtfCate = new JTextField(20);
- JTextArea motoArea = new JTextArea(5,40);
- JTextArea motoArea2 = new JTextArea(5,40);
- JButton mFind = new JButton("Find");
- JButton mAdd = new JButton("Add");
- JButton mUpdate = new JButton("Update");
- JButton mClear = new JButton("Clear");
- JButton mDelete = new JButton("Delete");
- JButton mAudit = new JButton("Audit");
- //Invoice
- JLabel employeeId = new JLabel("Employee ID");
- JLabel customerId = new JLabel("Customer ID");
- JLabel invoiceDate = new JLabel("Invoice Date");
- JLabel total = new JLabel("Total");
- JTextField jtfEmployeeId = new JTextField(20);
- JTextField jtfCustomerId = new JTextField(20);
- JTextField jtfInvoiceDate = new JTextField(20);
- JTextField jtfTotal = new JTextField(20);
- JButton iFind = new JButton("Find");
- JButton iAdd = new JButton("Add");
- JButton iUpdate = new JButton("Update");
- JButton iClear = new JButton("Clear");
- JButton iDelete = new JButton("Delete");
- JButton iAudit = new JButton("Audit");
- JTextArea invArea = new JTextArea(5,40);
- JTextArea invArea2 = new JTextArea(5,40);
- //Moto-Cust
- JLabel mcusID = new JLabel("Customer ID");
- JLabel mID = new JLabel("Moto ID");
- JTextField jtfCusId = new JTextField(20);
- JTextField jtfMID = new JTextField(20);
- JButton mcAdd = new JButton("Add");
- JButton mcDelete = new JButton("Delete");
- JTextArea mcArea = new JTextArea(5, 40);
- JTextArea mcArea2 = new JTextArea(5, 40);
- public CycleBusinessGUI(){
- //Employee Panel
- JPanel employ = new JPanel(new GridLayout(9,2));
- employ.add(ID);
- employ.add(jtfID);
- employ.add(firstName);
- employ.add(firstN);
- employ.add(lastName);
- employ.add(lastN);
- employ.add(expertise);
- employ.add(exper);
- employ.add(yearHired);
- employ.add(yearH);
- employ.add(supervisor);
- employ.add(superV);
- employ.add(phone);
- employ.add(phoneN);
- employ.add(email);
- employ.add(emailA);
- employ.add(relation);
- employ.add(relaS);
- JPanel ebuttonPanel = new JPanel(new GridLayout(1,6));
- ebuttonPanel.add(find);
- ebuttonPanel.add(update);
- ebuttonPanel.add(add);
- ebuttonPanel.add(clear);
- ebuttonPanel.add(delete);
- ebuttonPanel.add(audit);
- find.addActionListener(this);
- add.addActionListener(this);
- delete.addActionListener(this);
- clear.addActionListener(this);
- update.addActionListener(this);
- audit.addActionListener(this);
- JPanel area = new JPanel(new FlowLayout());
- area.add(jspDescript);
- JPanel area2 = new JPanel(new FlowLayout());
- area2.add(jspDescript2);
- JPanel eComplete = new JPanel(new FlowLayout());
- eComplete.add(employ);
- eComplete.add(area);
- eComplete.add(ebuttonPanel);
- eComplete.add(area2);
- //Customer Panel
- JPanel customer = new JPanel(new GridLayout(8,2));
- customer.add(cusID);
- customer.add(cusIDI);
- customer.add(name);
- customer.add(n);
- customer.add(creditRating);
- customer.add(creditR);
- //NOTE: Make new phone. Caused code confusion//
- customer.add(cPhone);
- customer.add(cPhoneN);
- customer.add(address);
- customer.add(addressN);
- customer.add(city);
- customer.add(cityW);
- customer.add(state);
- customer.add(stateW);
- customer.add(zip);
- customer.add(zipC);
- JPanel cbuttonPanel = new JPanel(new GridLayout(1,6));
- cbuttonPanel.add(cFind);
- cbuttonPanel.add(cUpdate);
- cbuttonPanel.add(cAdd);
- cbuttonPanel.add(cClear);
- cbuttonPanel.add(cDelete);
- //cbuttonPanel.add(cAudit);
- cFind.addActionListener(this);
- cUpdate.addActionListener(this);
- cAdd.addActionListener(this);
- cClear.addActionListener(this);
- cDelete.addActionListener(this);
- JPanel cComplete = new JPanel(new FlowLayout());
- cComplete.add(customer);
- cComplete.add(cusArea);
- cComplete.add(cbuttonPanel);
- cComplete.add(cusArea2);
- //Motorcycle//////////////////////////////////////////////
- JPanel motorcycle = new JPanel(new GridLayout(5,2));
- motorcycle.add(motoID);
- motorcycle.add(jtfmoto);
- motorcycle.add(info);
- motorcycle.add(jtfInfo);
- motorcycle.add(manu);
- motorcycle.add(jtfManu);
- motorcycle.add(msrp);
- motorcycle.add(jtfMsrp);
- motorcycle.add(cate);
- motorcycle.add(jtfCate);
- JPanel mbuttonPanel = new JPanel(new GridLayout(1,6));
- mbuttonPanel.add(mFind);
- mbuttonPanel.add(mUpdate);
- mbuttonPanel.add(mAdd);
- mbuttonPanel.add(mClear);
- mbuttonPanel.add(mDelete);
- mFind.addActionListener(this);
- mAdd.addActionListener(this);
- mUpdate.addActionListener(this);
- mClear.addActionListener(this);
- mDelete.addActionListener(this);
- JPanel mComplete = new JPanel(new FlowLayout());
- mComplete.add(motorcycle);
- mComplete.add(motoArea);
- mComplete.add(mbuttonPanel);
- mComplete.add(motoArea2);
- //Invoice
- JPanel invoice = new JPanel(new GridLayout(4,2));
- invoice.add(employeeId);
- invoice.add(jtfEmployeeId);
- invoice.add(customerId);
- invoice.add(jtfCustomerId);
- invoice.add(invoiceDate);
- invoice.add(jtfInvoiceDate);
- invoice.add(total);
- invoice.add(jtfTotal);
- JPanel ibuttonPanel = new JPanel(new GridLayout(1,6));
- ibuttonPanel.add(iFind);
- ibuttonPanel.add(iUpdate);
- ibuttonPanel.add(iAdd);
- ibuttonPanel.add(iClear);
- ibuttonPanel.add(iDelete);
- iFind.addActionListener(this);
- iClear.addActionListener(this);
- JPanel iComplete = new JPanel(new FlowLayout());
- iComplete.add(invoice);
- iComplete.add(invArea);
- iComplete.add(ibuttonPanel);
- iComplete.add(invArea2);
- JPanel motocust = new JPanel(new GridLayout(2,2));
- motocust.add(mcusID);
- motocust.add(jtfCusId);
- motocust.add(mID);
- motocust.add(jtfMID);
- JPanel mcbuttonPanel = new JPanel (new GridLayout(1, 2));
- mcbuttonPanel.add(mcAdd);
- mcbuttonPanel.add(mcDelete);
- mcAdd.addActionListener(this);
- mcDelete.addActionListener(this);
- JPanel mcComplete = new JPanel(new FlowLayout());
- mcComplete.add(motocust);
- mcComplete.add(mcArea);
- mcComplete.add(mcbuttonPanel);
- mcComplete.add(mcArea2);
- jtpComplete.add(eComplete, "Employee");
- jtpComplete.add(cComplete,"Customer");
- jtpComplete.add(mComplete,"Motorcycle");
- jtpComplete.add(iComplete,"Invoice");
- jtpComplete.add(mcComplete, "Moto-Cust");
- jtpComplete.setToolTipTextAt(0,"Eploy");
- jtpComplete.setToolTipTextAt(1,"Cus");
- jtpComplete.setToolTipTextAt(2,"Moto");
- jtpComplete.setToolTipTextAt(3,"Invo");
- jtpComplete.setToolTipTextAt(4, "MoCust");
- add(jtpComplete);
- }
- public static void main(String args[]) throws SQLException,ClassNotFoundException{
- JFrame frame = new CycleBusinessGUI();
- frame.setTitle(" ");
- frame.setLocationRelativeTo(null);
- frame.setSize(550, 550);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- public void actionPerformed(ActionEvent e){
- if (e.getSource() == cFind){
- System.out.println("Customer Find Button Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "SELECT * FROM Customer WHERE(CustomerID LIKE '"
- + cusIDI.getText()+ "%') AND (Name LIKE '"
- + n.getText() + "%') AND (CreditRating LIKE '"
- + creditR.getText() + "%') AND (Phone LIKE '"
- + cPhoneN.getText() + "%') AND (Address LIKE '"
- + addressN.getText() + "%') AND (City LIKE '"
- + cityW.getText() + "%') AND (State LIKE '"
- + stateW.getText() + "%') AND (ZipCode LIKE '"
- + zipC.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- cusArea2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == find){
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "SELECT * FROM Employee WHERE(EmployeeID LIKE '"
- + jtfID.getText()+ "%') AND (FirstName LIKE '"
- + firstN.getText() + "%') AND (LastName LIKE '"
- + lastN.getText() + "%') AND (Expertise LIKE '"
- + exper.getText() + "%') AND (YearHired LIKE '"
- + yearH.getText() + "%') AND (Supervisor LIKE '"
- + superV.getText() + "%') AND (PhoneNumber LIKE '"
- + phoneN.getText() + "%') AND (Email LIKE '"
- + emailA.getText() + "%') AND (RStatus LIKE '"
- + relaS.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == mFind){
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "SELECT * FROM Motorcycle WHERE(MotoID LIKE '"
- + jtfmoto.getText()+ "%') AND (Description LIKE '"
- + jtfInfo.getText() + "%') AND (Manufacturer LIKE '"
- + jtfManu.getText() + "%') AND (MSRP LIKE '"
- + jtfMsrp.getText() + "%') AND (Category LIKE '"
- + jtfCate.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- motoArea2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + "\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- System.out.println("ClassNotFoundException Error");
- }
- catch(SQLException ex){
- System.out.println("SQLException Error");
- }
- }
- if (e.getSource() == iFind){
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "SELECT * FROM Invoice WHERE(EmployeeID LIKE '"
- + jtfEmployeeId.getText()+ "%') AND (CustomerID LIKE '"
- + jtfCustomerId.getText() + "%') AND (InvDate LIKE '"
- + jtfInvoiceDate.getText() + "%') AND (Total LIKE '"
- + jtfTotal.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- invArea2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + "\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- System.out.println("ClassNotFoundException Error");
- }
- catch(SQLException ex){
- System.out.println("SQLException Error");
- }
- }
- if (e.getSource() == add){
- System.out.println("Employee Add Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "Insert INTO Employee(EmployeeID,FirstName,LastName,Expertise ,YearHired,Supervisor,"
- + "PhoneNumber,Email ,RStatus)VALUES( '" + jtfID.getText() + "','" + firstN.getText() + "','"
- + lastN.getText() + "','" + exper.getText() + "','"
- + yearH.getText() + "','" + superV.getText() + "','"
- + phoneN.getText() + "','" + emailA.getText() + "','" + relaS.getText() + "')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == cAdd){
- System.out.println("Customer Add Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "Insert INTO Customer(CustomerID,Name,CreditRating,Phone ,Address,City,"
- + "State,ZipCode)VALUES( '" + cusIDI.getText() + "','" + n.getText() + "','"
- + creditR.getText() + "','" + cPhoneN.getText() + "','"
- + addressN.getText() + "','" + cityW.getText() + "','"
- + stateW.getText() + "','" + zipC.getText() + "')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == delete){
- System.out.println("Employee Delete Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "DELETE * FROM Employee WHERE(EmployeeID LIKE '"
- + jtfID.getText()+ "%') AND (FirstName LIKE '"
- + firstN.getText() + "%') AND (LastName LIKE '"
- + lastN.getText() + "%') AND (Expertise LIKE '"
- + exper.getText() + "%') AND (YearHired LIKE '"
- + yearH.getText() + "%') AND (Supervisor LIKE '"
- + superV.getText() + "%') AND (PhoneNumber LIKE '"
- + phoneN.getText() + "%') AND (Email LIKE '"
- + emailA.getText() + "%') AND (RStatus LIKE '"
- + relaS.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == cDelete){
- System.out.println("Customer Delete Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "DELETE * FROM Customer WHERE(CustomerID LIKE '"
- + cusIDI.getText()+ "%') AND (Name LIKE '"
- + n.getText() + "%') AND (CreditRating LIKE '"
- + creditR.getText() + "%') AND (Phone LIKE '"
- + cPhoneN.getText() + "%') AND (Address LIKE '"
- + addressN.getText() + "%') AND (City LIKE '"
- + cityW.getText() + "%') AND (State LIKE '"
- + stateW.getText() + "%') AND (ZipCode LIKE '"
- + zipC.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- if (e.getSource() == mcDelete){
- System.out.println("Moto-Cust Delete Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "DELETE * FROM MotoCust WHERE(CustomerID LIKE '"
- + mcusID.getText()+ "%') AND (MotoID LIKE '"
- + motoID.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- mcArea2.append(rset.getString(1) + " " + rset.getString(2)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if (e.getSource() == mcAdd){
- System.out.println("Moto-Cust Add Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- System.out.println("Moto - Cust Add Clicked");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "Insert INTO Moto-Cust(CustomerID,MotoID) VALUES ( '" + mcusID.getText() + "','" + mID.getText() + "')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- mcArea2.append(rset.getString(1) + " " + rset.getString(2)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- if(e.getSource() == clear){
- System.out.println("Employee Clear Clicked");
- descript2.setText(null);
- }
- if(e.getSource() == cClear){
- System.out.println("Customer Clear Clicked");
- cusArea2.setText(null);
- }
- if(e.getSource() == mClear){
- System.out.println("Motorcycle Clear Clicked");
- motoArea2.setText(null);
- }
- if(e.getSource() == iClear){
- System.out.println("Invoice Clear Clicked");
- invArea2.setText(null);
- }
- if(e.getSource() == cUpdate){
- System.out.println("Customer Update Clicked");
- try{
- // Load the JDBC driver
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:odbc:CycleBusiness");
- System.out.println("Database connected");
- //if statements for strings
- // Create a statement
- Statement stmt = connection.createStatement();
- String myString = "UPDATE Customer SET CustomerID ="
- + cusIDI.getText()+ "WHERE TITLE = CustomerID AND SET Name ="
- + n.getText() + "WHERE TITLE = NAME AND AND SET CreditRating ="
- + creditR.getText() + "WHERE TITLE = CreditRating AND SET Phone ="
- + cPhoneN.getText() + "WHERE TITLE = Phone AND SET AND SET Name = AND SET Name ="
- + addressN.getText() + "%') AND (City LIKE '"
- + cityW.getText() + "%') AND (State LIKE '"
- + stateW.getText() + "%') AND (ZipCode LIKE '"
- + zipC.getText() + "%')";
- System.out.println(myString);
- // Select the columns from the Student table
- ResultSet rset = stmt.executeQuery(myString);
- // Iterate through the result and print the student names
- while (rset.next())
- descript2.append(rset.getString(1) + " " + rset.getString(2)
- + " " + rset.getString(3)+ " " + rset.getString(4)
- + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
- // close the connection
- connection.close();
- }
- catch(ClassNotFoundException ex){
- }
- catch(SQLException ex){
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement