1.11M Members

updating quantity

 
0
 

i hav a shopping cart in java he columns of jtable are
code-the item code
qty-the quantity enterd by the user
i want to update the quantity in database .the description of the table is
code -item code
stock-total stock in hand.
i need to to update the quantity by making te total stock lesser(i.e stock-qty) when i click the button finished shopping.
thankyou

 
0
 

So, what's the problem you are having?

 
0
 

the problem is it shows mysql syntax error exception -you have an error in your sql syntax

 
0
 

can you tell me the method of doing it without having this error.

 
0
 

the best way would be to re-write your sql code. but correct, this time.

 
0
 
DefaultTableModel tm=(DefaultTableModel)cartbl.getModel();
int r=cartbl.getRowCount();
for (int i=0 ;i<r;i++){
    String code=(String)cartbl.getValueAt(i,0);
    int q1=(Integer)cartbl.getValueAt(i, 3);
     try{
            Class.forName("java.sql.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bollywood","root","123456");
            Statement stmt=con.createStatement();
            String sql="select qty from albums where acode='"+code+"' ;";
            ResultSet rs=stmt.executeQuery(sql);
            rs.next();
            int q=rs.getInt("qty");
            int quant=q-q1;
            String sql2="update albums set qty="+quant+"where acode='"+code+"';";
            stmt.executeUpdate(sql2);
            }
         catch(Exception e){
           JOptionPane.showMessageDialog(null,e);  
         }

Quoted Text Here
i tried finding the error in sql coding but could not.

 
0
 

String sql2="update albums set qty="+quant+"where acode='"+code+"';";

There is no space before where.

Next time post your error message too.

 
0
 

thanks a ton .i am really sorry to have botherd you because of my silly error.God bless.

Question Answered as of 1 Year Ago by pritaeas and stultuske
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article