Der Versuch, herauszufinden, was der Fehler in diesem Java-Code ist.MySQL Java-Syntaxfehler
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)'
Die Reihenfolge Tisch sieht aus wie
order_id int pk ai <br>
item_quantity <br>
customer_id int <br>
product_id int <br>
Und die Funktion, die ist fügt:
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());
}
}
Jede Hilfe wäre sehr dankbar, kann nicht scheinen, um dies herauszufinden.
Könntest du bitte die 'order' rückklicken? – 1000111
[ORDER ist ein reserviertes Wort] (http://dev.mysql.com/doc/refman/5.0/en/keywords.html). Schreibe "Ordnung" anstatt "Ordnung". – Satya
Ohne Bezug zu diesem spezifischen Problem, aber als _soon_, wenn Sie anfangen, sich mit dieser Art von SQL vertraut zu machen, sollten Sie sich PreparedStatements ansehen. Sie bieten Ihnen mehr Sicherheit (wenn Ihre 'int'-Argumente Strings wären, würde ich mich sofort über einen SQL-Injection-Angriff wundern). – yshavit