【发布时间】:2016-05-27 08:38:15
【问题描述】:
我需要一些帮助才能在我的两个表之间建立连接
我这样填表“tanden”
public void addTandenToDatabase(int id, int fdi, String voorstelling, String toestand) {
String insertSql = "insert into tanden(id, fdi, voorstelling, toestand) values (:idVal, :fdiVal, :voorstellingVal, :toestandVal)";
try (Connection con = sql2o.open()) {
con.setRollbackOnException(false);
con.createQuery(insertSql)
.addParameter("idVal", id)
.addParameter("fdiVal", fdi)
.addParameter("voorstellingVal", voorstelling)
.addParameter("toestandVal", toestand)
.executeUpdate();
}
}
一切都很好地添加了,但 idPatient 保持为空
【问题讨论】:
-
idPatient 不包含在您的 INSERT 查询的值中。你没有指定它。您是否希望以某种方式自动检索它?
-
是的,但是我如何指定它
-
您至少需要插入一个病人。然后,知道它的 id,将其用作 tanden 中 idPatient 列的值。