Trying to figure out what the error is in this java code.
The SQLException reads: " 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 'order (item_quantity, customer_id, product_id) VALUES (5, 191, 31)'
The order table looks like
order_id int pk ai <br>
item_quantity <br>
customer_id int <br>
product_id int <br>
And the function that inserts is:
public void createOrder(int productQuantity, int customerId, int productId) throws SQLException {
sql = "INSERT INTO order (item_quantity, customer_id, product_id) VALUES (" + productQuantity + ", " + customerId + ", " + productId + ")";
try {
int a = stmt.executeUpdate(sql);
if (a == 1) {
System.out.println("Order Added");
} else {
System.out.println("Order Failed");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
Any help would be greatly appreciated, can't seem to figure this out.
order?'Order'insteadorder.intargs were Strings, I would immediately be wondering about a SQL injection attack).