问题
I'm trying to execute the sql query:
INSERT INTO celebrity (name, `1`, `15`, `3`, `20`, `4`, `13`, `35`, `22`, `6`, `19`) VALUES ("Keith Allen", 1, 1, 1, 1, 1, -1, -1, -1, -1, 1)
which worked fine in the workbench and correctly added the new row, however when I call the same query from java using the executeUpdate(String query) method, I get a sql syntax error
回答1:
You need to escape your double quotes like this:
INSERT INTO celebrity (name, `1`, `15`, `3`, `20`, `4`, `13`, `35`, `22`, `6`, `19`)
VALUES (\"Keith Allen\", 1, 1, 1, 1, 1, -1, -1, -1, -1, 1)
来源:https://stackoverflow.com/questions/29340015/mysql-query-gives-syntax-error-in-java-but-works-fine-in-mysql-workbench