We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,289 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

updating quantity

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

3
Contributors
7
Replies
3 Hours
Discussion Span
5 Months Ago
Last Updated
8
Views
Question
Answered
angel sunflower
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

So, what's the problem you are having?

pritaeas
Posting Prodigy
Moderator
9,309 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86

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

angel sunflower
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

angel sunflower
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

stultuske
Industrious Poster
4,379 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
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.

angel sunflower
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

There is no space before where.

Next time post your error message too.

pritaeas
Posting Prodigy
Moderator
9,309 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86

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

angel sunflower
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by pritaeas and stultuske

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0891 seconds using 2.7MB