Dylanbeginner21 Dylanbeginner21 - 1 year ago 52
SQL Question

SQL update - gets an error

For a Netbeans project I need to update mySQL database with JavaFX project.
I can add an Account, but I cant seem to edit one.

Here is the methode that gives an error but I cant see what I am doing wrong.
Maybe the SQL syntax is wrong and thats where I need a hand.

public void wijzigenAccount(Account teWijzigenAccount) throws DBException {
try(Connection conn = ConnectionManager.getConnection();){
try(PreparedStatement stmt = conn.prepareStatement("UPDATE Account SET (naam, voornaam,login,paswoord,emailadres) values(?,?,?,?,?) WHERE naam = " + teWijzigenAccount.getNaam() +";");){
stmt.setString(1, teWijzigenAccount.getNaam());
stmt.setString(2, teWijzigenAccount.getVoornaam());
stmt.setString(3, teWijzigenAccount.getLogin());
stmt.setString(4, teWijzigenAccount.getPaswoord());
stmt.setString(5, teWijzigenAccount.getEmailadres());
} catch (SQLException ex) {
throw new DBException("SQLException opgetreden in statement: " +ex.getMessage());
} catch (SQLException ex){
throw new DBException("SQLException opgetreden in connectie " + ex.getMessage());

I am new to this so give me a break, I am learning step by step.

This is an image of the MySQL database
enter image description here

Thanks already for the help.

Answer Source

That is syntax for INSERT not for UPDATE. Try this way

UPDATE Account SET naam = ?,
                   voornaam = ?,
                   login = ?,
                   paswoord = ?,
                   emailadres = ? 
WHERE naam = " + teWijzigenAccount.getNaam()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download