Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.56 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.sql.*;
  4. import java.awt.event.*;
  5.  
  6. public class CycleBusinessGUI extends JFrame implements ActionListener {
  7. //Employee
  8. JLabel ID = new JLabel("Employee ID");
  9. JTextField jtfID = new JTextField(20);
  10. JLabel firstName = new JLabel("First Name");
  11. JLabel lastName = new JLabel("Last Name");
  12. JLabel expertise = new JLabel("Expertise");
  13. JLabel yearHired = new JLabel("Year Hired");
  14. JLabel supervisor = new JLabel("Supervisor");
  15. JLabel phone = new JLabel("Phone Number");
  16. JLabel email = new JLabel("Email Address");
  17. JLabel relation = new JLabel("Relationship Status");
  18. JTextField firstN = new JTextField(20);
  19. JTextField lastN = new JTextField(20);
  20. JTextField exper = new JTextField(20);
  21. JTextField yearH = new JTextField(20);
  22. JTextField superV = new JTextField(20);
  23. JTextField phoneN = new JTextField(20);
  24. JTextField emailA = new JTextField(20);
  25. JTextField relaS = new JTextField(20);
  26. JTextArea descript = new JTextArea(5,40);
  27. JTextArea descript2 = new JTextArea(5,40);
  28. JScrollPane jspDescript = new JScrollPane(descript);
  29. JScrollPane jspDescript2 = new JScrollPane(descript2);
  30. JButton find = new JButton("Find");
  31. JButton add = new JButton("Add");
  32. JButton update = new JButton("Update");
  33. JButton clear = new JButton("Clear");
  34. JButton delete = new JButton("Delete");
  35. JButton audit = new JButton("Audit");
  36.  
  37. //Customer
  38. JTextField creditR = new JTextField(20);
  39. JTextField addressN = new JTextField(20);
  40. JTextField cityW = new JTextField(20);
  41. JTextField stateW = new JTextField(20);
  42. JTextField zipC = new JTextField(20);
  43. JTextField n = new JTextField(20);
  44. JTextField cPhoneN = new JTextField(20);
  45. JTextField cusIDI = new JTextField(20);
  46. JTextArea cusArea = new JTextArea(5,40);
  47. JTextArea cusArea2 = new JTextArea(5,40);
  48. JButton cFind = new JButton("Find");
  49. JButton cAdd = new JButton("Add");
  50. JButton cUpdate = new JButton("Update");
  51. JButton cClear = new JButton("Clear");
  52. JButton cDelete = new JButton("Delete");
  53. JButton cAudit = new JButton("Audit");
  54. JLabel creditRating = new JLabel("Credit Rating");
  55. JLabel address = new JLabel("Address");
  56. JLabel city = new JLabel("City");
  57. JLabel state = new JLabel("State");
  58. JLabel zip = new JLabel("Zip Code");
  59. JLabel name = new JLabel("Name");
  60. JLabel cPhone = new JLabel("Phone");
  61. JLabel cusID = new JLabel("Customer ID");
  62. JTabbedPane jtpComplete = new JTabbedPane();
  63. //MotoCycle
  64.  
  65. JLabel motoID = new JLabel("Moto ID");
  66. JLabel info = new JLabel("Description");
  67. JLabel manu = new JLabel("Manufacturer");
  68. JLabel msrp = new JLabel("MSRP");
  69. JLabel cate = new JLabel("Category");
  70. JTextField jtfmoto = new JTextField(20);
  71. JTextField jtfInfo = new JTextField(20);
  72. JTextField jtfManu = new JTextField(20);
  73. JTextField jtfMsrp = new JTextField(20);
  74. JTextField jtfCate = new JTextField(20);
  75. JTextArea motoArea = new JTextArea(5,40);
  76. JTextArea motoArea2 = new JTextArea(5,40);
  77. JButton mFind = new JButton("Find");
  78. JButton mAdd = new JButton("Add");
  79. JButton mUpdate = new JButton("Update");
  80. JButton mClear = new JButton("Clear");
  81. JButton mDelete = new JButton("Delete");
  82. JButton mAudit = new JButton("Audit");
  83.  
  84. //Invoice
  85. JLabel employeeId = new JLabel("Employee ID");
  86. JLabel customerId = new JLabel("Customer ID");
  87. JLabel invoiceDate = new JLabel("Invoice Date");
  88. JLabel total = new JLabel("Total");
  89. JTextField jtfEmployeeId = new JTextField(20);
  90. JTextField jtfCustomerId = new JTextField(20);
  91. JTextField jtfInvoiceDate = new JTextField(20);
  92. JTextField jtfTotal = new JTextField(20);
  93. JButton iFind = new JButton("Find");
  94. JButton iAdd = new JButton("Add");
  95. JButton iUpdate = new JButton("Update");
  96. JButton iClear = new JButton("Clear");
  97. JButton iDelete = new JButton("Delete");
  98. JButton iAudit = new JButton("Audit");
  99. JTextArea invArea = new JTextArea(5,40);
  100. JTextArea invArea2 = new JTextArea(5,40);
  101. //Moto-Cust
  102. JLabel mcusID = new JLabel("Customer ID");
  103. JLabel mID = new JLabel("Moto ID");
  104. JTextField jtfCusId = new JTextField(20);
  105. JTextField jtfMID = new JTextField(20);
  106. public CycleBusinessGUI(){
  107. //Employee Panel
  108. JPanel employ = new JPanel(new GridLayout(9,2));
  109. employ.add(ID);
  110. employ.add(jtfID);
  111. employ.add(firstName);
  112. employ.add(firstN);
  113. employ.add(lastName);
  114. employ.add(lastN);
  115. employ.add(expertise);
  116. employ.add(exper);
  117. employ.add(yearHired);
  118. employ.add(yearH);
  119. employ.add(supervisor);
  120. employ.add(superV);
  121. employ.add(phone);
  122. employ.add(phoneN);
  123. employ.add(email);
  124. employ.add(emailA);
  125. employ.add(relation);
  126. employ.add(relaS);
  127. JPanel ebuttonPanel = new JPanel(new GridLayout(1,6));
  128. ebuttonPanel.add(find);
  129. ebuttonPanel.add(update);
  130. ebuttonPanel.add(add);
  131. ebuttonPanel.add(clear);
  132. ebuttonPanel.add(delete);
  133. ebuttonPanel.add(audit);
  134. find.addActionListener(this);
  135. add.addActionListener(this);
  136. delete.addActionListener(this);
  137. clear.addActionListener(this);
  138. update.addActionListener(this);
  139. audit.addActionListener(this);
  140. JPanel area = new JPanel(new FlowLayout());
  141. area.add(jspDescript);
  142. JPanel area2 = new JPanel(new FlowLayout());
  143. area2.add(jspDescript2);
  144. JPanel eComplete = new JPanel(new FlowLayout());
  145. eComplete.add(employ);
  146. eComplete.add(area);
  147. eComplete.add(ebuttonPanel);
  148. eComplete.add(area2);
  149.  
  150. //Customer Panel
  151. JPanel customer = new JPanel(new GridLayout(8,2));
  152. customer.add(cusID);
  153. customer.add(cusIDI);
  154. customer.add(name);
  155. customer.add(n);
  156. customer.add(creditRating);
  157. customer.add(creditR);
  158. //NOTE: Make new phone. Caused code confusion//
  159. customer.add(cPhone);
  160. customer.add(cPhoneN);
  161. customer.add(address);
  162. customer.add(addressN);
  163. customer.add(city);
  164. customer.add(cityW);
  165. customer.add(state);
  166. customer.add(stateW);
  167. customer.add(zip);
  168. customer.add(zipC);
  169. JPanel cbuttonPanel = new JPanel(new GridLayout(1,6));
  170. cbuttonPanel.add(cFind);
  171. cbuttonPanel.add(cUpdate);
  172. cbuttonPanel.add(cAdd);
  173. cbuttonPanel.add(cClear);
  174. cbuttonPanel.add(cDelete);
  175. //cbuttonPanel.add(cAudit);
  176. cFind.addActionListener(this);
  177. cUpdate.addActionListener(this);
  178. cAdd.addActionListener(this);
  179. cClear.addActionListener(this);
  180. cDelete.addActionListener(this);
  181.  
  182. JPanel cComplete = new JPanel(new FlowLayout());
  183. cComplete.add(customer);
  184. cComplete.add(cusArea);
  185. cComplete.add(cbuttonPanel);
  186. cComplete.add(cusArea2);
  187.  
  188.  
  189. //Motorcycle//////////////////////////////////////////////
  190. JPanel motorcycle = new JPanel(new GridLayout(5,2));
  191. motorcycle.add(motoID);
  192. motorcycle.add(jtfmoto);
  193. motorcycle.add(info);
  194. motorcycle.add(jtfInfo);
  195. motorcycle.add(manu);
  196. motorcycle.add(jtfManu);
  197. motorcycle.add(msrp);
  198. motorcycle.add(jtfMsrp);
  199. motorcycle.add(cate);
  200. motorcycle.add(jtfCate);
  201. JPanel mbuttonPanel = new JPanel(new GridLayout(1,6));
  202. mbuttonPanel.add(mFind);
  203. mbuttonPanel.add(mUpdate);
  204. mbuttonPanel.add(mAdd);
  205. mbuttonPanel.add(mClear);
  206. mbuttonPanel.add(mDelete);
  207. mFind.addActionListener(this);
  208. mAdd.addActionListener(this);
  209. mUpdate.addActionListener(this);
  210. mClear.addActionListener(this);
  211. mDelete.addActionListener(this);
  212.  
  213. JPanel mComplete = new JPanel(new FlowLayout());
  214. mComplete.add(motorcycle);
  215. mComplete.add(motoArea);
  216. mComplete.add(mbuttonPanel);
  217. mComplete.add(motoArea2);
  218.  
  219.  
  220. //Invoice
  221. JPanel invoice = new JPanel(new GridLayout(4,2));
  222. invoice.add(employeeId);
  223. invoice.add(jtfEmployeeId);
  224. invoice.add(customerId);
  225. invoice.add(jtfCustomerId);
  226. invoice.add(invoiceDate);
  227. invoice.add(jtfInvoiceDate);
  228. invoice.add(total);
  229. invoice.add(jtfTotal);
  230.  
  231. JPanel ibuttonPanel = new JPanel(new GridLayout(1,6));
  232. ibuttonPanel.add(iFind);
  233. ibuttonPanel.add(iUpdate);
  234. ibuttonPanel.add(iAdd);
  235. ibuttonPanel.add(iClear);
  236. ibuttonPanel.add(iDelete);
  237. iFind.addActionListener(this);
  238. iClear.addActionListener(this);
  239.  
  240. JPanel iComplete = new JPanel(new FlowLayout());
  241. iComplete.add(invoice);
  242. iComplete.add(invArea);
  243. iComplete.add(ibuttonPanel);
  244. iComplete.add(invArea2);
  245.  
  246. JPanel motocust = new JPanel(new GridLayout(2,2));
  247. motocust.add(mcusID);
  248. motocust.add(jtfCusId);
  249. motocust.add(mID);
  250. motocust.add(jtfMID);
  251.  
  252. jtpComplete.add(eComplete, "Employee");
  253. jtpComplete.add(cComplete,"Customer");
  254. jtpComplete.add(mComplete,"Motorcycle");
  255. jtpComplete.add(iComplete,"Invoice");
  256.  
  257. jtpComplete.setToolTipTextAt(0,"Eploy");
  258. jtpComplete.setToolTipTextAt(1,"Cus");
  259. jtpComplete.setToolTipTextAt(2,"Moto");
  260. jtpComplete.setToolTipTextAt(3,"Invo");
  261. add(jtpComplete);
  262. }
  263.  
  264. public static void main(String args[]) throws SQLException,ClassNotFoundException{
  265. JFrame frame = new CycleBusinessGUI();
  266. frame.setTitle(" ");
  267. frame.setLocationRelativeTo(null);
  268. frame.setSize(550, 550);
  269. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  270. frame.setLocationRelativeTo(null);
  271. frame.setVisible(true);
  272.  
  273.  
  274.  
  275. }
  276. public void actionPerformed(ActionEvent e){
  277. if (e.getSource() == cFind){
  278. System.out.println("Customer Find Button Clicked");
  279.  
  280. try{
  281. // Load the JDBC driver
  282. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  283. System.out.println("Driver loaded");
  284.  
  285.  
  286. // Establish a connection
  287. Connection connection = DriverManager.getConnection
  288. ("jdbc:odbc:CycleBusiness");
  289. System.out.println("Database connected");
  290. //if statements for strings
  291.  
  292.  
  293. // Create a statement
  294. Statement stmt = connection.createStatement();
  295.  
  296. String myString = "SELECT * FROM Customer WHERE(CustomerID LIKE '"
  297. + cusIDI.getText()+ "%') AND (Name LIKE '"
  298. + n.getText() + "%') AND (CreditRating LIKE '"
  299. + creditR.getText() + "%') AND (Phone LIKE '"
  300. + cPhoneN.getText() + "%') AND (Address LIKE '"
  301. + addressN.getText() + "%') AND (City LIKE '"
  302. + cityW.getText() + "%') AND (State LIKE '"
  303. + stateW.getText() + "%') AND (ZipCode LIKE '"
  304. + zipC.getText() + "%')";
  305.  
  306. System.out.println(myString);
  307. // Select the columns from the Student table
  308. ResultSet rset = stmt.executeQuery(myString);
  309.  
  310.  
  311. // Iterate through the result and print the student names
  312. while (rset.next())
  313. cusArea2.append(rset.getString(1) + " " + rset.getString(2)
  314. + " " + rset.getString(3)+ " " + rset.getString(4)
  315. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  316.  
  317.  
  318. // close the connection
  319. connection.close();
  320. }
  321. catch(ClassNotFoundException ex){
  322. }
  323.  
  324.  
  325. catch(SQLException ex){
  326.  
  327. }
  328. }
  329. if (e.getSource() == find){
  330. try{
  331. // Load the JDBC driver
  332. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  333. System.out.println("Driver loaded");
  334.  
  335.  
  336. // Establish a connection
  337. Connection connection = DriverManager.getConnection
  338. ("jdbc:odbc:CycleBusiness");
  339. System.out.println("Database connected");
  340. //if statements for strings
  341.  
  342.  
  343. // Create a statement
  344. Statement stmt = connection.createStatement();
  345.  
  346. String myString = "SELECT * FROM Employee WHERE(EmployeeID LIKE '"
  347. + jtfID.getText()+ "%') AND (FirstName LIKE '"
  348. + firstN.getText() + "%') AND (LastName LIKE '"
  349. + lastN.getText() + "%') AND (Expertise LIKE '"
  350. + exper.getText() + "%') AND (YearHired LIKE '"
  351. + yearH.getText() + "%') AND (Supervisor LIKE '"
  352. + superV.getText() + "%') AND (PhoneNumber LIKE '"
  353. + phoneN.getText() + "%') AND (Email LIKE '"
  354. + emailA.getText() + "%') AND (RStatus LIKE '"
  355. + relaS.getText() + "%')";
  356.  
  357. System.out.println(myString);
  358. // Select the columns from the Student table
  359. ResultSet rset = stmt.executeQuery(myString);
  360.  
  361.  
  362. // Iterate through the result and print the student names
  363. while (rset.next())
  364. descript2.append(rset.getString(1) + " " + rset.getString(2)
  365. + " " + rset.getString(3)+ " " + rset.getString(4)
  366. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  367.  
  368.  
  369. // close the connection
  370. connection.close();
  371. }
  372. catch(ClassNotFoundException ex){
  373. }
  374.  
  375.  
  376. catch(SQLException ex){
  377.  
  378. }
  379. }
  380. if (e.getSource() == mFind){
  381. try{
  382. // Load the JDBC driver
  383. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  384. System.out.println("Driver loaded");
  385.  
  386.  
  387. // Establish a connection
  388. Connection connection = DriverManager.getConnection
  389. ("jdbc:odbc:CycleBusiness");
  390. System.out.println("Database connected");
  391. //if statements for strings
  392.  
  393.  
  394. // Create a statement
  395. Statement stmt = connection.createStatement();
  396.  
  397. String myString = "SELECT * FROM Motorcycle WHERE(MotoID LIKE '"
  398. + jtfmoto.getText()+ "%') AND (Description LIKE '"
  399. + jtfInfo.getText() + "%') AND (Manufacturer LIKE '"
  400. + jtfManu.getText() + "%') AND (MSRP LIKE '"
  401. + jtfMsrp.getText() + "%') AND (Category LIKE '"
  402. + jtfCate.getText() + "%')";
  403.  
  404. System.out.println(myString);
  405. // Select the columns from the Student table
  406. ResultSet rset = stmt.executeQuery(myString);
  407.  
  408.  
  409. // Iterate through the result and print the student names
  410. while (rset.next())
  411. motoArea2.append(rset.getString(1) + " " + rset.getString(2)
  412. + " " + rset.getString(3)+ " " + rset.getString(4)
  413. + " " + rset.getString(5) + "\n");
  414.  
  415.  
  416. // close the connection
  417. connection.close();
  418. }
  419. catch(ClassNotFoundException ex){
  420. System.out.println("ClassNotFoundException Error");
  421. }
  422.  
  423.  
  424. catch(SQLException ex){
  425. System.out.println("SQLException Error");
  426. }
  427. }
  428.  
  429. if (e.getSource() == iFind){
  430. try{
  431. // Load the JDBC driver
  432. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  433. System.out.println("Driver loaded");
  434.  
  435.  
  436. // Establish a connection
  437. Connection connection = DriverManager.getConnection
  438. ("jdbc:odbc:CycleBusiness");
  439. System.out.println("Database connected");
  440. //if statements for strings
  441.  
  442.  
  443. // Create a statement
  444. Statement stmt = connection.createStatement();
  445.  
  446. String myString = "SELECT * FROM Invoice WHERE(EmployeeID LIKE '"
  447. + jtfEmployeeId.getText()+ "%') AND (CustomerID LIKE '"
  448. + jtfCustomerId.getText() + "%') AND (InvDate LIKE '"
  449. + jtfInvoiceDate.getText() + "%') AND (Total LIKE '"
  450. + jtfTotal.getText() + "%')";
  451.  
  452. System.out.println(myString);
  453. // Select the columns from the Student table
  454. ResultSet rset = stmt.executeQuery(myString);
  455.  
  456.  
  457. // Iterate through the result and print the student names
  458. while (rset.next())
  459. invArea2.append(rset.getString(1) + " " + rset.getString(2)
  460. + " " + rset.getString(3)+ " " + rset.getString(4)
  461. + "\n");
  462.  
  463.  
  464. // close the connection
  465. connection.close();
  466. }
  467. catch(ClassNotFoundException ex){
  468. System.out.println("ClassNotFoundException Error");
  469. }
  470.  
  471.  
  472. catch(SQLException ex){
  473. System.out.println("SQLException Error");
  474. }
  475. }
  476. if (e.getSource() == add){
  477. System.out.println("Employee Add Clicked");
  478. try{
  479. // Load the JDBC driver
  480. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  481. System.out.println("Driver loaded");
  482.  
  483.  
  484. // Establish a connection
  485. Connection connection = DriverManager.getConnection
  486. ("jdbc:odbc:CycleBusiness");
  487. System.out.println("Database connected");
  488. //if statements for strings
  489.  
  490.  
  491. // Create a statement
  492. Statement stmt = connection.createStatement();
  493.  
  494. String myString = "Insert INTO Employee(EmployeeID,FirstName,LastName,Expertise ,YearHired,Supervisor,"
  495. + "PhoneNumber,Email ,RStatus)VALUES( '" + jtfID.getText() + "','" + firstN.getText() + "','"
  496. + lastN.getText() + "','" + exper.getText() + "','"
  497. + yearH.getText() + "','" + superV.getText() + "','"
  498. + phoneN.getText() + "','" + emailA.getText() + "','" + relaS.getText() + "')";
  499.  
  500. System.out.println(myString);
  501. // Select the columns from the Student table
  502. ResultSet rset = stmt.executeQuery(myString);
  503.  
  504.  
  505. // Iterate through the result and print the student names
  506. while (rset.next())
  507. descript2.append(rset.getString(1) + " " + rset.getString(2)
  508. + " " + rset.getString(3)+ " " + rset.getString(4)
  509. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  510.  
  511.  
  512. // close the connection
  513. connection.close();
  514. }
  515. catch(ClassNotFoundException ex){
  516. }
  517.  
  518.  
  519. catch(SQLException ex){
  520.  
  521. }
  522. }
  523. if (e.getSource() == cAdd){
  524. System.out.println("Customer Add Clicked");
  525. try{
  526. // Load the JDBC driver
  527. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  528. System.out.println("Driver loaded");
  529.  
  530.  
  531. // Establish a connection
  532. Connection connection = DriverManager.getConnection
  533. ("jdbc:odbc:CycleBusiness");
  534. System.out.println("Database connected");
  535. //if statements for strings
  536.  
  537.  
  538. // Create a statement
  539. Statement stmt = connection.createStatement();
  540.  
  541. String myString = "Insert INTO Customer(CustomerID,Name,CreditRating,Phone ,Address,City,"
  542. + "State,ZipCode)VALUES( '" + cusIDI.getText() + "','" + n.getText() + "','"
  543. + creditR.getText() + "','" + cPhoneN.getText() + "','"
  544. + addressN.getText() + "','" + cityW.getText() + "','"
  545. + stateW.getText() + "','" + zipC.getText() + "')";
  546.  
  547. System.out.println(myString);
  548. // Select the columns from the Student table
  549. ResultSet rset = stmt.executeQuery(myString);
  550.  
  551.  
  552. // Iterate through the result and print the student names
  553. while (rset.next())
  554. descript2.append(rset.getString(1) + " " + rset.getString(2)
  555. + " " + rset.getString(3)+ " " + rset.getString(4)
  556. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  557.  
  558.  
  559. // close the connection
  560. connection.close();
  561. }
  562. catch(ClassNotFoundException ex){
  563. }
  564.  
  565.  
  566. catch(SQLException ex){
  567.  
  568. }
  569. }
  570.  
  571. if (e.getSource() == delete){
  572. System.out.println("Employee Delete Clicked");
  573. try{
  574. // Load the JDBC driver
  575. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  576. System.out.println("Driver loaded");
  577.  
  578.  
  579. // Establish a connection
  580. Connection connection = DriverManager.getConnection
  581. ("jdbc:odbc:CycleBusiness");
  582. System.out.println("Database connected");
  583. //if statements for strings
  584.  
  585.  
  586. // Create a statement
  587. Statement stmt = connection.createStatement();
  588.  
  589. String myString = "DELETE * FROM Employee WHERE(EmployeeID LIKE '"
  590. + jtfID.getText()+ "%') AND (FirstName LIKE '"
  591. + firstN.getText() + "%') AND (LastName LIKE '"
  592. + lastN.getText() + "%') AND (Expertise LIKE '"
  593. + exper.getText() + "%') AND (YearHired LIKE '"
  594. + yearH.getText() + "%') AND (Supervisor LIKE '"
  595. + superV.getText() + "%') AND (PhoneNumber LIKE '"
  596. + phoneN.getText() + "%') AND (Email LIKE '"
  597. + emailA.getText() + "%') AND (RStatus LIKE '"
  598. + relaS.getText() + "%')";
  599.  
  600. System.out.println(myString);
  601. // Select the columns from the Student table
  602. ResultSet rset = stmt.executeQuery(myString);
  603.  
  604.  
  605. // Iterate through the result and print the student names
  606. while (rset.next())
  607. descript2.append(rset.getString(1) + " " + rset.getString(2)
  608. + " " + rset.getString(3)+ " " + rset.getString(4)
  609. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  610.  
  611.  
  612. // close the connection
  613. connection.close();
  614. }
  615. catch(ClassNotFoundException ex){
  616. }
  617.  
  618.  
  619. catch(SQLException ex){
  620.  
  621. }
  622.  
  623.  
  624. }
  625. if (e.getSource() == cDelete){
  626. System.out.println("Customer Delete Clicked");
  627. try{
  628. // Load the JDBC driver
  629. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  630. System.out.println("Driver loaded");
  631.  
  632.  
  633. // Establish a connection
  634. Connection connection = DriverManager.getConnection
  635. ("jdbc:odbc:CycleBusiness");
  636. System.out.println("Database connected");
  637. //if statements for strings
  638.  
  639.  
  640. // Create a statement
  641. Statement stmt = connection.createStatement();
  642.  
  643. String myString = "DELETE * FROM Customer WHERE(CustomerID LIKE '"
  644. + cusIDI.getText()+ "%') AND (Name LIKE '"
  645. + n.getText() + "%') AND (CreditRating LIKE '"
  646. + creditR.getText() + "%') AND (Phone LIKE '"
  647. + cPhoneN.getText() + "%') AND (Address LIKE '"
  648. + addressN.getText() + "%') AND (City LIKE '"
  649. + cityW.getText() + "%') AND (State LIKE '"
  650. + stateW.getText() + "%') AND (ZipCode LIKE '"
  651. + zipC.getText() + "%')";
  652.  
  653. System.out.println(myString);
  654. // Select the columns from the Student table
  655. ResultSet rset = stmt.executeQuery(myString);
  656.  
  657.  
  658. // Iterate through the result and print the student names
  659. while (rset.next())
  660. descript2.append(rset.getString(1) + " " + rset.getString(2)
  661. + " " + rset.getString(3)+ " " + rset.getString(4)
  662. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  663.  
  664.  
  665. // close the connection
  666. connection.close();
  667. }
  668. catch(ClassNotFoundException ex){
  669. }
  670.  
  671.  
  672. catch(SQLException ex){
  673.  
  674. }
  675.  
  676.  
  677. }
  678.  
  679. if(e.getSource() == clear){
  680. System.out.println("Employee Clear Clicked");
  681. descript2.setText(null);
  682.  
  683. }
  684. if(e.getSource() == cClear){
  685. System.out.println("Customer Clear Clicked");
  686. cusArea2.setText(null);
  687.  
  688. }
  689. if(e.getSource() == mClear){
  690. System.out.println("Motorcycle Clear Clicked");
  691. motoArea2.setText(null);
  692.  
  693. }
  694. if(e.getSource() == iClear){
  695. System.out.println("Invoice Clear Clicked");
  696. invArea2.setText(null);
  697.  
  698. }
  699.  
  700. if(e.getSource() == cUpdate){
  701. System.out.println("Customer Update Clicked");
  702. try{
  703. // Load the JDBC driver
  704. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  705. System.out.println("Driver loaded");
  706.  
  707.  
  708. // Establish a connection
  709. Connection connection = DriverManager.getConnection
  710. ("jdbc:odbc:CycleBusiness");
  711. System.out.println("Database connected");
  712. //if statements for strings
  713.  
  714.  
  715. // Create a statement
  716. Statement stmt = connection.createStatement();
  717.  
  718. String myString = "UPDATE Customer SET CustomerID ="
  719. + cusIDI.getText()+ "WHERE TITLE = CustomerID AND SET Name ="
  720. + n.getText() + "WHERE TITLE = NAME AND AND SET CreditRating ="
  721. + creditR.getText() + "WHERE TITLE = CreditRating AND SET Phone ="
  722. + cPhoneN.getText() + "WHERE TITLE = Phone AND SET AND SET Name ="AND SET Name ="AND SET Name ="
  723. + addressN.getText() + "%') AND (City LIKE '"
  724. + cityW.getText() + "%') AND (State LIKE '"
  725. + stateW.getText() + "%') AND (ZipCode LIKE '"
  726. + zipC.getText() + "%')";
  727.  
  728. System.out.println(myString);
  729. // Select the columns from the Student table
  730. ResultSet rset = stmt.executeQuery(myString);
  731.  
  732.  
  733. // Iterate through the result and print the student names
  734. while (rset.next())
  735. descript2.append(rset.getString(1) + " " + rset.getString(2)
  736. + " " + rset.getString(3)+ " " + rset.getString(4)
  737. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  738.  
  739.  
  740. // close the connection
  741. connection.close();
  742. }
  743. catch(ClassNotFoundException ex){
  744. }
  745.  
  746.  
  747. catch(SQLException ex){
  748.  
  749. }
  750.  
  751.  
  752. }
  753.  
  754.  
  755.  
  756. }
  757.  
  758.  
  759.  
  760. }
  761. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement