Linux下MySQL JDBC事物处理不成功
package test;import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import com.tarena.util.database.DBConnection;
public class TranTest {
public static void main(String[] args) {
Connection conn = null;
Statement stat = null;
try {
conn = DBConnection.getConnection();
String sql1 = "update zzq_emp set salary=salary+1000 where id=1";
String sql2 = "update zzq_emp set salary=salary-1000 where id=3";
// 设置事务为手动提交
conn.setAutoCommit(false);
stat = conn.createStatement();
int result1 = stat.executeUpdate(sql1);
int result2 = stat.executeUpdate(sql2);
if(result1==1&&result2==1){
// 提交事务
conn.commit();
}else{
conn.rollback();
}
System.out.println("执行成功");
} catch (Exception e) {
e.printStackTrace();
try {
// 回滚事务
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
} finally {
try {
DBConnection.close(stat, conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
这段代码在windows下可以的,在linux下怎么不能用呢?跪求各位 --------------------编程问答-------------------- linux下mysql用的什么引擎,像ISAM和MyISAM之类的是不支持事务的,InnoDB支持事务
补充:Java , Web 开发