我正在使用JDBC(使用mysql)测试java中的回滚,但下面的代码无效。代码的行为就好像我调用了commit()而不是rollback()。有人能告诉我哪里出错了吗?
Connection conn=null;
try
{
conn = SqlConnectionHandler.getSqlConnection();
conn.setAutoCommit(false);
}
catch(Exception e)
{
System.exit(-1);
}
String updateString1 = "update files set ownerID=ownerID+1 where globalFileID=2";
String updateString2 = "update directories set size=size+1 where globalDirID=8";
try
{
Statement statement = conn.createStatement();
statement.executeUpdate(updateString1);
statement.executeUpdate(updateString2);
conn.rollback();
//conn.commit();
statement.close();
SqlConnectionHandler.closeConnection(conn);
}
catch(Exception ex)
{
System.err.println("SQLException: " + ex.getMessage());
try
{
conn.rollback();
}
catch(SQLException e)
{}
}
}