Results 1 to 7 of 7
  1. #1
    blustar angel is offline Member
    Join Date
    Aug 2012
    Posts
    17
    Blog Entries
    1
    Rep Power
    0

    Default help with shoppingcart

    [QUOTE]how do i increase the quatity of an item when it is added again and again into my shopping cart table.there is only a button add to cart.there is no textfeild for quantitiy.
    the code as of now i have retreives the items from database and add it into the shipping cart table. if i clik on it again and again the same item wil be shown again and again.
    Java Code:
    DefaultTableModel model = (DefaultTableModel) tbl1.getModel();
                DefaultTableModel tm = (DefaultTableModel) tbl2.getModel();
                int a = tbl1.getSelectedRow();
                if (a == 0) {
                    
                    try {
                        Class.forName("java.sql.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bollywood", "root", "123");
                        Statement stm = con.createStatement();
                        String sql = "select ALBUMNAME,PRICE FROM albums WHERE ALBUMNAME='TWILIGHT' ;";
                        ResultSet res = stm.executeQuery(sql);
                        while (res.next()) {
                            String ALBUMNAME = res.getString("ALBUMNAME");
                            int PRICE = res.getInt ("PRICE");
    
                            tm.addRow(new Object[]{ALBUMNAME, PRICE});
                        }
                        res.close();
                        con.close();
                        stm.close();
                        
    
    
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "error");
                    }
    I HAVE A COLUMN NAME QUANTITY. THE NUMBER SHOULD INCREASE WHEN THE SAME ITEM IS ADDED.
    Last edited by blustar angel; 08-29-2012 at 03:35 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: help with shoppingcart

    You need to have a way to test if the item is already being shown.
    If not, add it with a quantity of 1
    If it is shown, increment the quantity by 1
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    blustar angel is offline Member
    Join Date
    Aug 2012
    Posts
    17
    Blog Entries
    1
    Rep Power
    0

    Default Re: help with shoppingcart

    how do i test if the item is shown .can you give me begining.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: help with shoppingcart

    Post a small simple program that compiles, executes and shows the problem. Something that can be worked with to see how to solve your problem.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    blustar angel is offline Member
    Join Date
    Aug 2012
    Posts
    17
    Blog Entries
    1
    Rep Power
    0

    Default Re: help with shoppingcart

    sorry ,i dint get u.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: help with shoppingcart

    I don't understand what you don't get about my post#4.

    For testing I need a small, complete program that compiles,
    and executes
    and shows the problem.

    You need to create a small program I can use for testing the problem and working on a solution.


    See: http://sscce.org/
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: help with shoppingcart

    Go through the table and see if there's a row in there containing the data already?

    The API has at least one good method to get you started on that...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •