Start New Discussion within our Software Development Community

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.

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

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);
            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);
            int q=rs.getInt("qty");
            int quant=q-q1;
            String sql2="update albums set qty="+quant+"where acode='"+code+"';";
         catch(Exception e){

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

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

There is no space before where.

Next time post your error message too.

This question has already been answered. Start a new discussion instead.