@Test public void testFailedTransactionRollback() throws SQLException { connection.setAutoCommit(false); // Failed statement mockConnection.setError(42, "bad"); Statement s = connection.createStatement(); try { s.executeUpdate("DELETE bad"); fail("expected exception"); } catch (SQLException e) { } assertNull(mockConnection.lastFinish); // All future statements should also fail mockConnection.setUpdateCount(42); try { s.executeUpdate("DELETE good"); fail("expected exception"); } catch (SQLException e) { } connection.enableStrictMode(true); try { connection.commit(); fail("expected exception"); } catch (SQLException e) { } // rollback this transaction connection.rollback(); assertNull(mockConnection.lastFinish); try { // Can't rollback: no transaction! connection.rollback(); fail("expected exception"); } catch (SQLException e) { } assertEquals(42, s.executeUpdate("DELETE good")); }