Try running this program:
connection.setAutoCommit(true);
try {
try (Statement s = connection.createStatement()) {
s.executeUpdate("drop table if exists t");
s.executeUpdate("create table t (i int not null)");
}
try (Statement s = connection.createStatement()) {
s.addBatch("insert into t values (null)");
s.executeBatch();
}
}
finally {
try (Statement s = connection.createStatement()) {
s.executeUpdate("drop table t");
}
}
It produces this error on the drop table t statement:
java.sql.SQLException: TransactionContext Error: Current transaction is aborted (please ROLLBACK)
at org.duckdb.DuckDBNative.duckdb_jdbc_execute(Native Method)
at org.duckdb.DuckDBPreparedStatement.execute(DuckDBPreparedStatement.java:178)
at org.duckdb.DuckDBPreparedStatement.execute(DuckDBPreparedStatement.java:155)
at org.duckdb.DuckDBPreparedStatement.executeLargeUpdate(DuckDBPreparedStatement.java:229)
at org.duckdb.DuckDBPreparedStatement.executeLargeUpdate(DuckDBPreparedStatement.java:259)
at org.duckdb.DuckDBPreparedStatement.executeUpdate(DuckDBPreparedStatement.java:252)
at org.jooq.testscripts.JDBC.main(JDBC.java:73)
The problem is that the s.executeBatch() call fails with a constraint violation exception, which seems to abort an internal transaction. But I set the auto commit flag to true explicitly, so I don't think the user should have to recover from this problem, it should be handled internally inside of executeBatch().
Note:
- This doesn't happen with ordinary statement execution, only with batches.
- This is a regression in version 1.3.0.0 of the driver. The problem didn't happen yet in 1.1.3 or 1.2.2.0 yet