天天看點

mysql 復原失敗_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我期待着工作的承諾。

但是,如果更新語句發生錯誤,插入語句正在運作。

哪裡不對?