title: mysql jdbc unsuccessful rollback
body: <p>I've got some Java code uses JDBC to connect to a MySQL database, then the code does some read operations then a single update, all using the same connection. If there is an exception, then <code>connection.rollback()</code> is called; if there's no exception, <code>connection.commit()</code> is called. At this stage, the connection is newly created each time I run my test (i.e. it does not come from a pool). My code only ever creates one connection, and it is used throughout the test.</p>
  
  <p>The connection being used has <code>connection.setAutoCommit(false)</code> called immediately after the connection instance is created.</p>
  
  <p>For some reason, when there is an exception and <code>connection.rollback()</code> is called, it turns out that my update has been committed rather than rolled back.</p>
  
  <p>Via debugging, I have confirmed the following,</p>
  
  <ul>
  <li><p>After calling <code>connection.setAutoCommit(false)</code>, <code>connection.getAutoCommit()</code> returns a value of <code>false</code>, as expected. Also, <code>"Select @@session.autocommit"</code> returns a value of <code>0</code>, indicating that auto commit is off, as expected.</p></li>
  <li><p>Immediately prior to calling <code>connection.rollback()</code>, the same checks show that auto commit is off, as expected.</p></li>
  <li><p><code>connection.commit()</code> is definitely not being called and <code>connection.rollback()</code> is definitely being called.</p></li>
  </ul>
  
  <p>I have also tried explicitly running the statement <code>"rollback;"</code> but it does not solve my issue. I have also tried explicitly running the statement <code>"Set AUTOCOMMIT = 0;"</code> after creating the connection.</p>
  
  <p>All of my tables use a storage engine of InnoDB. Via SQL Workbench, with auto commit off, rollbacks and commits work as expected.</p>
  
  <p>I am using MySQL version '5.0.91-community-nt'. The MySQL jdbc driver version is 5.1.19. I'm using Java 5.</p>
  
  <p>Has anyone got any suggestions as to why my update is getting committed even though auto-commit is off, commit is never called, and rollback is explicitly called?</p>
  
  <p>Cheers.</p>