mySQL query gives syntax error in java, but works fine in mySQL workbench

时光怂恿深爱的人放手 提交于 2019-12-11 15:03:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!