https://i.stack.imgur.com/Pd3pu.jpg
I have two comboboxes (ploegid and trainerid) stored with data. Don't worry about the ploegID and trainerID who are given as parameters are correct.
I want to set trainer_id on table ploeg where id = ? But I also want the connected table (persoon) to be updated!
Table persoon has to be like this: update persoon set ploeg_id = ? where ? is the parameter ploegID
how can i do this in one update statement? inner joins?
public void voegTrainerAanPloeg(Integer ploegid, Integer trainerid) throws
DBException {
// connectie tot stand brengen (en automatisch sluiten)
try (Connection conn = ConnectionManager.getConnection();) {
// preparedStatement opstellen (en automtisch sluiten)
try (PreparedStatement stmt = conn.
prepareStatement(
"update ploeg set trainer_id = ? where id=?");) {
stmt.setInt(1, trainerid);
stmt.setInt(2, ploegid);
// execute voert elke sql-statement uit, executeQuery enkel de select
stmt.execute();
} catch (SQLException sqlEx) {
throw new DBException("SQL-exception in verwijderRekening");
}
} catch (SQLException sqlEx) {
throw new DBException(
"SQL-exception in verwijderRekening - connection");
}
}