Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void saveExpenses() {
- actionListener = new ActionListener() {
- public void actionPerformed(ActionEvent actionEvent) {
- try {
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/computer_inventory","root","");
- PreparedStatement pstate = con.prepareStatement("INSERT INTO sales"+" VALUES (?,?,?,?,?,?)");
- pstate.setString(1, view.tf9.getText());
- pstate.setString(2, view.tf6.getText());
- pstate.setString(3, view.tf7.getText());
- pstate.setString(4, view.lTotal2.getText());
- pstate.executeUpdate();
- JOptionPane.showInputDialog(view,"Successfully Added");
- view.tf9.setText("");
- view.tf6.setText("");
- view.tf7.setText("");
- view.lTotal2.setText("");
- getData();
- con.close();
- }catch(SQLException ex) {
- ex.printStackTrace();
- JOptionPane.showInputDialog(view,"Error");
- }
- }
- };
- view.getDlyButton().addActionListener(actionListener);
- }
- public void getData() {
- try {
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/computer_inventory","root","");
- Statement st = con.createStatement();
- String query = "SELECT * FROM sales";
- ResultSet rs = st.executeQuery(query);
- while(rs.next()) {
- String ProductName = rs.getString("ProductName");
- String Price = rs.getString("Price");
- String Quantity = rs.getString("Quantity");
- String TotalSale = rs.getString("TotalSale");
- view.ta1.append(" The: "+ProductName +" With an indivual price of: "+Price+" peso"+" Ang bought : "+Quantity+" pieces"
- +" have a total cost of: "+ TotalSale+" nn");
- }
- }
- catch(SQLException ex) {
- ex.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment