将数据插入我的数据库后,数据库会自动生成ID,我希望将其返回给我。但我不知道怎么......
public Integer addPerson(person p) throws DBException {
try (Connection conn = ConnectionManager.getConnection();) {
try (PreparedStatement stmt = conn.prepareStatement(
"insert into klant(name, date) values (?,?)");) {
stmt.setString(1, p.getName());
stmt.setObject(2, Date.valueOf(p.getDate()));
stmt.execute();
} catch (SQLException s) {
throw new DBException(s);
}
} catch (SQLException s) {
throw new DBException(s);
}
return id_generated_by_db;
}