Yenots1
Yenots1

Reputation: 15

SQL Syntax error when running DELETE from Java

I get error ERROR: syntax error at or near "("

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));

Upvotes: 1

Views: 110

Answers (1)

Langusten Gustel
Langusten Gustel

Reputation: 11002

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));

The problem are the missing spaces while concatinating.

Imagine the following:

"word" + "word2"

this would result "wordword2"

so it should be

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

Upvotes: 5

Related Questions