0

After inserting data into my database the database automatically generates and ID which I would like to get returned to me. But I have no idea how...

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;
}

0 Answers0