Issue
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.
@Override
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());
stmt.execute();
} 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
Thanks already for the help.
Solution
That is syntax for INSERT
not for UPDATE
. Try this way
UPDATE Account SET naam = ?,
voornaam = ?,
login = ?,
paswoord = ?,
emailadres = ?
WHERE naam = " + teWijzigenAccount.getNaam()
Answered By - Pரதீப்