扣除股票

时间:2017-04-15 13:30:56

标签: java swing compiler-errors

我有JTable作为订单窗格。当我完成订单并点击JButton调用"新订单"它会清除JTable并清除订单细节,例如价格和更改等。当我点击" New Order"时,我想要做什么? JButton将扣除在清算之前在最后一个订单中出售的库存。

我的SQL数据库中有一个表,其中包含名为

的列的产品

ProductID (PK), ProductName, ProductDescrp, Type, SupplierName, Quantity, Price

我所有这一切的目标是减少订单中已售出的任何产品的数据库中的Quantity库存。到目前为止,这是我的代码。

jbtNewOrder.addActionListener(new ActionListener() 
        {
            public void actionPerformed(ActionEvent e) 
            {
                    if(e.getSource().equals(jbtNewOrder)) 
            {
                total = 0.0;
                totalTF.setText("");
                tenderedTF.setText("");
                changeTF.setText("");
                model.setRowCount(0);

            try
            {
                int prodID = 0;
                String sql = ("UPDATE product " + "SET Quantity = Quantity -1" + (getDBQuantity(prodID)-1) + " WHERE ProductID = " + prodID);
                databaseUpdate(sql);
            }
            catch(Exception e1)
            {
                e1.printStackTrace();
            }
              return status;
           }

        // return quantity of a product in DB
            public int getDBQuantity(int prodID)
            {
                int quantity=0;
                try
                {
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = (Connection) DriverManager.getConnection(DB_URL, USER_NAME, PASSWORD);

                statement = (Statement) conn.createStatement();
                resultSet = statement.executeQuery("select Quantity from team_project.product WHERE ProductID = " + prodID);

                while (resultSet.next())
                {       
                    quantity = (resultSet.getInt("Quantity"));
                }
                conn.close();
                }catch(Exception e)
                {
                    e.printStackTrace();
                }
                return quantity;
                }}


     private int databaseUpdate(String sqlUpdate)
       {
          int status = 0;

          try{
             Class.forName("com.mysql.jdbc.Driver");
             Connection conn = (Connection) DriverManager.getConnection(DB_URL, USER_NAME, PASSWORD);
             statement = conn.createStatement();
             status = statement.executeUpdate(sqlUpdate);
             conn.close(); 
          }       

          catch (Exception e) {
             e.printStackTrace();
          }   
          return status;
       }

0 个答案:

没有答案