I have a problem.
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
I was expect working commit.
But If an error occurs update statement, insert statement is running.
What is wrong?
I think that you are using MyISAM table instead of InnoDB. MyISAM does not support transaction at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.