Results 1 to 4 of 4
  1. #1
    Dcalladi is offline Member
    Join Date
    Oct 2011
    Posts
    27
    Rep Power
    0

    Default SQL Statement Error

    Hi, i have a SQL statement that is meant to decrease a value of a certain item with using the items same in the where

    Java Code:
    Iterator itr = items.iterator();
            while (itr.hasNext()) {
                try {
                    DriverManager.registerDriver(new com.mysql.jdbc.Driver());
                    Connection conn = DriverManager.getConnection("jdbc:mysql://samp.inf.brad.ac.uk/dcalladi", "dcalladi", "Dannys21");
                    pstmt = conn.prepareStatement("UPDATE Test_items SET Stock_Level = Stock_Level - 1, WHERE Name = ?");
                    pstmt.setString(1, itr.next().toString());
                    pstmt.executeUpdate();
                    pstmt.close();
                    conn.close();
                } catch (Exception ex) {
                    System.err.println("SQLException: " + ex.getMessage());
                }
            }
        }
    so i have an arraylist called items, i want to pass through that array list with an iterator and with every item i want to subtract 1 from the stock were in the SQL statment name is taken from the arraylist. for some reason i am getting a

    SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE Name = 'Sweet Chilli Sauce'' at line 1

    error and dont have a clue why.

    and help would be appriciated

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: SQL Statement Error

    What's that comma doing in the SQL?
    You're only SETting one thing...

  3. #3
    Dcalladi is offline Member
    Join Date
    Oct 2011
    Posts
    27
    Rep Power
    0

    Default Re: SQL Statement Error

    totally skipped it didn't even realise works now, Thank you very much.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: SQL Statement Error

    No problem.
    We all get code blindness from time to time.

Similar Threads

  1. Syntax error in UPDATE statement Need Help!
    By mathidioticz in forum New To Java
    Replies: 7
    Last Post: 01-21-2012, 06:48 PM
  2. Error: if statement
    By nandhinianand in forum NetBeans
    Replies: 2
    Last Post: 08-07-2011, 05:32 PM
  3. error while using sql update statement
    By jttslg in forum Advanced Java
    Replies: 14
    Last Post: 07-03-2011, 10:38 PM
  4. error in if statement
    By carman12 in forum New To Java
    Replies: 11
    Last Post: 12-25-2010, 01:13 AM
  5. Return statement error
    By Exothesis in forum New To Java
    Replies: 2
    Last Post: 10-13-2010, 01:56 AM

Posting Permissions

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