从Java运行DELETE时出现SQL语法错误

时间:2013-11-02 13:36:50

标签: java sql

我收到错误错误:语法错误在“(”

处或附近
String deleteSQL = "DELETE FROM customer" +
"WHERE (fname = 'Fred' AND lname = 'Flintstone')" +
"OR (fname = 'Barney' AND lname = 'Rubble')";
System.out.println("Records deleted: "
+ stmt.executeUpdate(deleteSQL));

1 个答案:

答案 0 :(得分:5)

String deleteSQL = "DELETE FROM customer " +
"WHERE (fname = 'Fred' AND lname = 'Flintstone') " +
"OR (fname = 'Barney' AND lname = 'Rubble') ";
System.out.println("Records deleted: "
+ stmt.executeUpdate(deleteSQL));

问题是在结合时缺少空格

想象一下:

  

“word”+“word2”

这会导致"wordword2"

所以它应该是

"word" + " " + "word2" "word "+ "word2"