void test() throws WhateverException { Transaction my_transaction; my_transaction.startTransaction(); my_transaction.execute( new AutoRollback() { public void runQueries() throws Throwable { ... perform your queries: can be more than one, complex code, etc. ... ... local variables from the enclosing scope can be used as long as they are final... }}); my_transaction.commit(); }