Subject Re: [Firebird-Java] BatchUpdateException when ex ecuting PreparedStatements with executeBatch
Author Mark Rotteveel
On 3-9-2016 13:56, andreschuetz@... [Firebird-Java] wrote:
> I guess, I found the problem after your request to post my code. The
> preparedStatement was created as follows:
>
> val insertTableRow = "INSERT INTO accounts (id, name, description,
> birthday, salary) VALUES(?, ?, ?, ?, ?)"
>
> val preparedInsertStatement: PreparedStatement =
> connection.prepareStatement(insertTableRow, Statement.RETURN_GENERATED_KEYS)
>
> I think the "Statement.RETURN_GENERATED_KEYS" is not correct.
>
> I changed the parameter to "Statement.NO_GENERATED_KEYS"

Thanks for that information.

Jaybird doesn't support Statement.RETURN_GENERATED_KEYS with batch
execution of prepared statement (and callable statement). It is only
supported with normal statement execution (assuming antlr-runtime is on
the classpath).

Using Statement.RETURN_GENERATED_KEYS (or another generated keys option)
with batch execution results in an BatchUpdateException without an
exception message in Jaybird 2.2. I will add a more explicit exception
in Jaybird 2.2 (see http://tracker.firebirdsql.org/browse/JDBC-451)

In Jaybird 3 (3.0.0-alpha-1) this no longer results in an exception, but
it still isn't really supported: you will just be able to get generated
keys (or all columns) of the last inserted row. I will see if I can
improve that (see http://tracker.firebirdsql.org/browse/JDBC-452).

As an aside: using batch execution doesn't really have a performance
benefit, so if you do need to obtain generated keys, just use the normal
executeUpdate() for each row.

Mark
--
Mark Rotteveel