Quantcast
Channel: MySQL Forums - Connector/J, JDBC and Java
Viewing all articles
Browse latest Browse all 884

JDBC and Rollbacks with Savepoints (no replies)

$
0
0
Hello,

I got a problem rollback changes over my JDBC-connection. I am not using any super-user and the Tables are of engine=innoDB.

Problem ist, that after a failure in executeBatch no rollbakc can be done, because the savepoint cant be found.


### I forgot: Many thanks in advance.

Here are some fragments of my code:

Connection conn = DatabaseConnection.getConnection();
Statement stmt = null;

Savepoint sp = null;

try {

conn.setAutoCommit(false);

try {
sp = conn.setSavepoint("sp1");
} catch (SQLException e) {
log.error("Error creating savepoint: ", e);
}

[...]

while ((str = in.readLine()) != null) {

if (log.isDebugEnabled())
log.debug("#SQL-Statement: " + str);

stmt.addBatch(str);
}

in.close();

result = stmt.executeBatch();

conn.commit();

} catch (BatchUpdateException e) {
try {
log.error("Error in SQL-Script: ",e);
if (sp!=null) {
log.debug("Doing rollback with SavePoint.");
conn.rollback(sp);
}
else {
log.debug("Doing normal rollback without SavePoint.");
conn.rollback();
}
conn.commit();
return false;
} catch (Exception te) {
log.debug("Rollback konnte nicht durchgeführt werden! ", te);
}
}
catch (Exception ex) {
log.error("Script: " + filePath + " was not able to be commited to database!");
log.error("ExecuteDatabaseScript: ", ex);
return false;
} finally {
try {
if (sp!=null && conn!=null) conn.releaseSavepoint(sp);
} catch (SQLException e) {
log.error("Error releasing savepoint: ", e);
}
DatabaseConnection.closeStatement(stmt);
DatabaseConnection.closeConnection(conn);
}

Viewing all articles
Browse latest Browse all 884

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>