Veske
Veske

Reputation: 557

SQL prepared statement throwing an error about syntax

So I am using SQL with phpMyAdmin. Now I want to make an update to my database with a prepared statement but doind it gives me the following error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'autor='Lol' WHERE id=44' at line 1

And this is how my statement looks like:

command = connection.prepareStatement("UPDATE books SET name=? author=? WHERE id=?");
command.setString(1, name.getText());
command.setString(2, author.getText());
command.setInt(3, IDx);
command.execute();

Wat is wrong with the statement I have made? It should be working In my opinion.

Upvotes: 0

Views: 145

Answers (2)

Salah
Salah

Reputation: 8657

You need to separate the updated fields in a comma like:

 command = connection.prepareStatement("UPDATE books SET name=?, author=? WHERE id=?");

Upvotes: 2

juergen d
juergen d

Reputation: 204894

You forgot a comma before author

UPDATE books 
SET name = ?, author = ?
WHERE id = ?

Upvotes: 1

Related Questions