title: Distributing statements for a JDBC transaction in multiple methods
body: <p>I need to do a considerably long JDBC transaction. Can I distribute the statements required for the transaction in multiple methods, like this?</p>
  
  <pre><code>try {
      // ... Get connection
      // Start transaction
      connection.setAutoCommit(false);
      // In every one of these methods a series of statements is executed
      // All methods throw a SQLException which is caught here for rollback
      // Every method takes this connection as an argument
      method1(connection);
      method2(connection);
      // ...
      methodN(connection);
      // Commit all changes done inside the methods
      connection.commit();
  } catch (SQLException e) {
      connection.rollback();
  } finally {
      connection.setAutoCommit(true);
      connection.close();
  }
  </code></pre>