Statement stmt = connection.createStatement();  stmt.executeUpdate("CREATE TABLE test(id INTEGER, test_value INTEGER)"); stmt.executeUpdate("INSERT INTO test VALUES (1, 1)");  connection.setAutoCommit(false);  stmt.executeUpdate("UPDATE test SET test_value = 2 WHERE id = 1");  stmt.close();  connection.close();
try { Statement stmt = connection.createStatement();  stmt.executeUpdate("CREATE TABLE test(id INTEGER, test_value INTEGER)"); stmt.executeUpdate("INSERT INTO test VALUES (1, 1)");  connection.setAutoCommit(false);  stmt.executeUpdate("UPDATE test SET test_value = 2 WHERE id = 1");  stmt.close(); } finally { connection.close(); }
    public void testClose() throws Exception {        connection = getConnectionViaDriverManager();                Statement stmt = connection.createStatement();                stmt.executeUpdate("CREATE TABLE test(id INTEGER, test_value INTEGER)");        stmt.executeUpdate("INSERT INTO test VALUES (1, 1)");                connection.setAutoCommit(false);                stmt.executeUpdate("UPDATE test SET test_value = 2 WHERE id = 1");                stmt.close();                connection.close();                connection = getConnectionViaDriverManager();                stmt = connection.createStatement();                ResultSet rs = stmt.executeQuery("SELECT test_value FROM test WHERE id = 1");                assertTrue("Should have at least one row", rs.next());        assertTrue("Value should be 1.", rs.getInt(1) == 1);        assertTrue("Should have only one row.", !rs.next());                rs.close();        stmt.executeUpdate("DROP TABLE test");        stmt.close();        connection.close();    }