sql-streams icon indicating copy to clipboard operation
sql-streams copied to clipboard

Retrieving generated keys

Open bendem opened this issue 9 years ago • 1 comments

bendem avatar May 02 '16 15:05 bendem

Apparently, h2 doesn't support using executeQuery with DML statements, updateReturning solved that, but I removed it in https://github.com/bendem/sql-streams/commit/bbe9bf2477a48d129786a2da83c84f3adce596a8.

Need to consider if it's worth adding back vs using something like

try (Update update = sql.update(connection -> connection.prepareStatement("insert into table(column) values (?) returning *", Statement.RETURN_GENERATED_KEYS)).with(x)) {
    rejectIf(() -> update.count() != 1);
    try (ResultSet rs = update.getStatement().getGeneratedKeys()) {
        // deal with generated values here.
    }
}

bendem avatar May 17 '18 08:05 bendem