java - 在 Java 中检索 MySQL 自动增量

标签 java mysql jdbc sql2o

我正在尝试从数据库中检索 idPatient,但我不断收到错误,idPatient 是自动递增的。但我不知道这是否是导致问题的原因。

这是我正在尝试的代码

public List<Patient> getPatientsFromDatabase() {
    String sql = "SELECT naam, voornaam, gebit, idPatient from patienten";
    try (Connection con = sql2o.open()) {
        return con.createQuery(sql)
                .throwOnMappingFailure(false)
                .executeAndFetch(Patient.class);
    }
}

数据库:

enter image description here

错误:

enter image description here

编辑 - 患者:

public Patient(String voornaam, String naam, String gebit, int id) {
    this.voornaam = voornaam;
    this.naam = naam;
    this.id = id;
    if (null != gebit)switch (gebit) {
        case "melkgebit":
            g = new Melkgebit();
            this.gebit = "melkgebit";
            break;
        case "volwassengebit":
            g = new Volwassengebit();
            this.gebit = "volwassengebit";
            break;
        case "wisselgebit":
            this.gebit = "wisselgebit";
            break;
        default:
            break;
    }
}

最佳答案

Patient 似乎没有 idPatient 属性。检查一下

关于java - 在 Java 中检索 MySQL 自动增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37459980/

相关文章:

MySQL - 提高多国性能

sql - Insert if exists 只有在表中有记录时才有效

postgresql - 为什么连续读取的计数结果不同?

java - 调用 Postgres 存储函数 SQL 错误

java - 将巨大的包添加到新项目中(Eclipse)

python - 循环遍历具有两列且第一列中有重复条目的 .csv 文件的最佳方法?

java - 多维长度数组反射java

sql - MySQL 中无符号 smallint(6) 的最大值是多少?

java - 无法解析符号 'window' 错误

java 。从抽象集合的ArrayList生成swt.table