0

I need to write a query to update a row in the database. but exception is

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Erreur de syntaxe pr?s de 'SET eMail = '11111', SET phoneNumber = '111111' WHERE name = 'Saba', surname= 'M' ? la ligne 1 .

what is the problem?

public static void updateUser(User user, Connection connection) throws SQLException {
PreparedStatement ps = null;
ps = connection.prepareStatement("UPDATE USERS SET login = ?, SET eMail = ?, SET phoneNumber = ? WHERE name = ?, surname= ?");
        ps.setString(1, user.getLogin());
        ps.setString(2, user.geteMail());
        ps.setString(3, user.getPhoneNumber());
        ps.setString(4, user.getName());
        ps.setString(5, user.getSurname());
        ps.executeUpdate();

1 Answer 1

1

The UPDATE statement only has a single SET clause. You repeated the SET keyword, which is wrong. Besides, you forgot the AND keyword to combine predicates. Write this instead:

try (PreparedStatement ps = connection.prepareStatement(
      "UPDATE USERS "
    + "SET login = ?, eMail = ?, phoneNumber = ? "
    + "WHERE name = ? AND surname = ?")) {

    // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.