【发布时间】:2015-08-03 17:50:41
【问题描述】:
我有两个存储有数据的组合框(ploegid 和 trainerid)。不用担心作为参数给出的 ploegID 和 trainerID 是否正确。
我想在 id = 的表 ploeg 上设置 trainer_id 但我也希望更新连接的表(人)!
table persoon 必须是这样的: update persoon set ploeg_id = ?在哪里 ?是参数ploegID
如何在一个更新语句中做到这一点?内连接?
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");
}
}
【问题讨论】: