Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
JDBC and Relational Databases
SQL Syntax Error for MySQL but not sure where...
Ron Ingram
Ranch Hand
Posts: 73
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can someone spot my error? I cannot seem to figure it out. Could be my
jdbc
driver, I'm currently using 5.1.14 jdbc driver.
public int update(String sku, String category, String description, String name, String price, String inventoryLevel, String brand, String gender, String size ) { int i; con = dbcon.SimpleConnection(); PreparedStatement ps = null; ResultSet rs; int prodId; try { System.out.println("Indise of ProductDB update() and sku variable =" + sku); //String queryID = "Select ProductId FROM Product WHERE sku = ?;"; String queryID = "SELECT ProductId FROM Product WHERE sku = '" + sku + "';"; //ps.setString(1, sku); //ps = con.prepareStatement(queryID); stmt = con.createStatement(); rs = stmt.executeQuery(queryID); //rs = ps.executeQuery(); rs.next(); System.out.println("Result Set inside of ProductDB update() =" + rs.toString()); prodId = Integer.parseInt(rs.getString("ProductId")); System.out.println("Product ID =" + prodId); } catch (SQLException sqex) { sqex.printStackTrace(); return i=-1; } //This method updates the record with a matching Product ID. //It returns a valurs = stmt.executeQuery(queryID)e of 0 if the email address can't be found. String query = "UPDATE Product SET " + "sku = ?, " + "Category = ?, " + "Description = ?, " + "Name = ?, " + "Price = ?, " + "InventoryLevel = ?, " + "Brand = ?, " + "Gender = ?, " + "Size = ?, " + "WHERE ProductId = ?"; try { ps = con.prepareStatement(query); ps.setString(1, sku); ps.setString(2, category); ps.setString(3, description); ps.setString(4, name); ps.setString(5, price); ps.setString(6, inventoryLevel); ps.setString(7, brand); ps.setString(8, gender); ps.setString(9, size); ps.setInt(10, prodId); i = ps.executeUpdate(); System.out.println(query); return i; } catch (SQLException e) { System.out.println(e); return -1; } finally { close.closeAll(); } }
Ron Ingram
Ranch Hand
Posts: 73
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is the actual stacktrace:
Product ID =1 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ProductId = 1' at line 1
Paul Clapham
Sheriff
Posts: 28362
99
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
My guess: the comma at line 52 (in your posted code).
Ron Ingram
Ranch Hand
Posts: 73
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
That was it! Must have been a copy & paste error for the last update variable.
Thank you for your help. R
Hot dog! An advertiser loves us THIS much:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
What is wrong?
Filtering Result Sets based on selectable links (a href:)
Out of Memory when testing a BMP Bean
Derby Embedded Database: errors in connection code
BMP, Jboss, and mysql configuring
More...