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

Recommended Answers

All 7 Replies

So, what's the problem you are having?

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

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

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

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.

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

There is no space before where.

Next time post your error message too.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.