java - 外键始终保持为空

标签 java mysql jdbc sql2o

我需要一些帮助来连接我的两个表

这些是“idPatient 是外键”的表 enter image description here

我这样填写表格“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 保持为空

enter image description here

最佳答案

如果要为其设置值,则应在 insert 中包含 idPatient。 '外键'并不意味着它将自动设置值。

关于java - 外键始终保持为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37478754/

相关文章:

java - 有没有办法使用 Maven 和 Junit 5 来​​暂存数据?

java - 从 jsp 调用方法时出错,但从 Java 类调用方法时出错

mysql jdbc 驱动程序不支持具有多个语句的触发器中的定界符

java - 从 NamedParameterJdbcTemplate 设置查询超时

java - 为什么从 super 接口(interface)到子接口(interface)的转换有效?

java - 并发加载文件时如何确定线程数

java - 海量IO操作服务器选择哪种技术

Mysql 选择所有与字符串中的数字匹配的内容

php - 从javascript函数获取复选框的值属性

php - 将值从 php 传递到 mysql,然后返回到 javascript