【问题标题】:jdbc rollback not workingjdbc回滚不起作用
【发布时间】:2010-10-26 22:00:25
【问题描述】:

我正在使用 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)
        {}
    }
}

【问题讨论】:

    标签: mysql jdbc transactions


    【解决方案1】:

    发现问题herehere。似乎我使用的是默认存储引擎 myISAM,它不支持事务。据报道,将存储引擎更改为 InnoDB 是可行的。

    【讨论】:

      猜你喜欢
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 2011-01-17
      • 2015-10-18
      相关资源
      最近更新 更多