Guest User

Untitled

a guest
Oct 8th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public void saveExpenses() {
  2. actionListener = new ActionListener() {
  3. public void actionPerformed(ActionEvent actionEvent) {
  4. try {
  5. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/computer_inventory","root","");
  6. PreparedStatement pstate = con.prepareStatement("INSERT INTO sales"+" VALUES (?,?,?,?,?,?)");
  7. pstate.setString(1, view.tf9.getText());
  8. pstate.setString(2, view.tf6.getText());
  9. pstate.setString(3, view.tf7.getText());
  10. pstate.setString(4, view.lTotal2.getText());
  11. pstate.executeUpdate();
  12. JOptionPane.showInputDialog(view,"Successfully Added");
  13. view.tf9.setText("");
  14. view.tf6.setText("");
  15. view.tf7.setText("");
  16. view.lTotal2.setText("");
  17. getData();
  18. con.close();
  19. }catch(SQLException ex) {
  20. ex.printStackTrace();
  21. JOptionPane.showInputDialog(view,"Error");
  22. }
  23. }
  24.  
  25. };
  26. view.getDlyButton().addActionListener(actionListener);
  27. }
  28.  
  29.  
  30. public void getData() {
  31. try {
  32. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/computer_inventory","root","");
  33. Statement st = con.createStatement();
  34. String query = "SELECT * FROM sales";
  35. ResultSet rs = st.executeQuery(query);
  36.  
  37. while(rs.next()) {
  38. String ProductName = rs.getString("ProductName");
  39. String Price = rs.getString("Price");
  40. String Quantity = rs.getString("Quantity");
  41. String TotalSale = rs.getString("TotalSale");
  42.  
  43. view.ta1.append(" The: "+ProductName +" With an indivual price of: "+Price+" peso"+" Ang bought : "+Quantity+" pieces"
  44. +" have a total cost of: "+ TotalSale+" nn");
  45. }
  46. }
  47. catch(SQLException ex) {
  48. ex.printStackTrace();
  49. }
  50. }
Add Comment
Please, Sign In to add comment