How would I get back all the inserted auto incremented id's on a batch insert using @SqlBatch? JDBI says that batch methods must either return void or int[] array with the array representing the number of rows modified within the batch.
PreparedStatement insertBatch = null;Connection connection = ....;for (Event event : events) {if (insertBatch == null){insertBatch = connection.prepareStatement("insert into `event` (game, `type`, actor, target, arg1, arg2, arg3, created) " +"values (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);}insertBatch.setObject(1, event.game);insertBatch.setString(2, event.type);insertBatch.setObject(3, event.actor);insertBatch.setObject(4, event.target);insertBatch.setString(5, event.arg1);insertBatch.setObject(6, event.arg2);insertBatch.setObject(7, event.arg3);insertBatch.setTimestamp(8, new Timestamp(event.created.getTime()));insertBatch.addBatch();}}if (insertBatch != null){insertBatch.executeBatch();ResultSet generatedKeys = insertBatch.getGeneratedKeys();for (Event event : events) {if ( generatedKeys == null || ! generatedKeys.next()){logger.warn("Unable to retrieve all generated keys");}event.id = generatedKeys.getLong(1);}logger.debug("events inserted");}
--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
How would you do this in JDBC?
Any update on this? I'm looking for something similar.Thanks,Paul
> Also, would it be interesting to merge the docs into the main repo, so that when we take PRs we can see doc changes alongside code changes?
I could get behind that. Ideally whatever we do should make it easy to put site documents on e.g. jdbi.github.io