I'm using Java 8, MySQL 5.6, Tomcat 7 (and its connection pool) and the MySQL J/Connector JDBC 5.1.35.
What I'm doing is calling three to six stored procedures (most are pure DML, some have SELECT statements intertwined with them). I set them up with prepareCall("{call NameOfTheStoredProcedute(?,?,...,?)}")
I execute two of them with executeQuery()
and the others with executeUpdate()
.
Before commit()
has been called, an exception is thrown and rollback()
is being called. At this point I would have expected the data in DB tables would be reverted, but that did not happen! Note that no exceptions were thrown during rollback.
Code path being executed:
final Context initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/eukm");
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
CallableStatement cs = conn.prepareCall("{call Store(?)}");
cs.setInt(1, 34);
ResultSet rs = cs.executeQuery();
rs.next();
int newId = rs.getInt(1);
rs.close();
cs.close();
cs = conn.prepareCall("{call Add(?, ?)}");
cs.setInt(1, 34);
cs.setInt(2, 1);
cs.executeUpdate();
cs.close();
conn.rollback();
conn.close();