2012-02-12 20 views
0

問題があります。MySQLのコミットとロールバックに失敗しました

try {     
    jdbcConnect(); //get mysql connect 
    conn.setAutoCommit(false); 

    pstmt = conn.prepareStatement ( 
        "INSERT INTO member (member_name, member_introduce) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS); 

    pstmt.setString(1, "something"); 
    pstmt.setString(2, "something"); 
    pstmt.executeUpdate(); 
    rs = pstmt.getGeneratedKeys(); 
    rs.next(); 
    String no = Integer.toString(rs.getInt(1); 

    pstmt = conn.prepareStatement ("UPDATE account SET account_name = ? WHERE account_no = ?"); 
    pstmt.setString(1, "something"); 
    pstmt.setString(2, no); 
    pstmt.executeUpdate(); 

    conn.commit();   
    conn.setAutoCommit(true); 

} catch (SQLException t) {    
    try { 
     if (conn != null) { 
      conn.rollback(); 
      conn.setAutoCommit(true); 
     } 
    } catch (SQLException e) { 
    } 
}//close conn and prepareStatement 

私はコミットを期待していました。

しかし、エラーが発生した場合、update文はinsert文が実行されています。

どうしたのですか?

答えて

4

InnoDBではなくMyISAMテーブルを使用していると思います。 MyISAMはトランザクションをまったくサポートしていません。

+0

ありがとうございます! @jdevelop – blim

+0

にスポットがあります。これは私の問題でした。 – Sonny

関連する問題