【问题标题】:MySQL commit and rollback failedMySQL 提交和回滚失败
【发布时间】:2012-03-04 03:34:29
【问题描述】:

我有问题。

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语句正在运行。

怎么了?

【问题讨论】:

    标签: java mysql jdbc commit rollback


    【解决方案1】:

    我认为您使用的是 MyISAM 表而不是 InnoDB。 MyISAM 根本不支持事务。

    【讨论】:

    • 正确。这是我的问题。
    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 2012-12-24
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 2013-09-14
    相关资源
    最近更新 更多