Results 1 to 4 of 4
Thread: SQL Statement Error
- 01-30-2012, 02:20 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 27
- Rep Power
- 0
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
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 aJava 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()); } } }
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
- 01-30-2012, 03:53 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
Re: SQL Statement Error
What's that comma doing in the SQL?
You're only SETting one thing...
- 01-30-2012, 04:07 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 27
- Rep Power
- 0
Re: SQL Statement Error
totally skipped it didn't even realise works now, Thank you very much.
- 01-30-2012, 04:38 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
Similar Threads
-
Syntax error in UPDATE statement Need Help!
By mathidioticz in forum New To JavaReplies: 7Last Post: 01-21-2012, 06:48 PM -
Error: if statement
By nandhinianand in forum NetBeansReplies: 2Last Post: 08-07-2011, 05:32 PM -
error while using sql update statement
By jttslg in forum Advanced JavaReplies: 14Last Post: 07-03-2011, 10:38 PM -
error in if statement
By carman12 in forum New To JavaReplies: 11Last Post: 12-25-2010, 01:13 AM -
Return statement error
By Exothesis in forum New To JavaReplies: 2Last Post: 10-13-2010, 01:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks