zhaolu 发表于 2018-12-23 06:22:34

PHP java MySQL 与 MsSQL 中的事务

//事务回滚  mysql_query("ROLLBACK");
  //事务提交
  mysql_query("COMMIT");
  MsSQL:
  //事务开始
  mssql_query("BEGIN TRANSACTION DEPS02_DEL");
  //事务回滚
  mssql_query("ROLLBACK TRANSACTION DEPS02_DEL");
  //事务提交
  mssql_query("COMMIT TRANSACTION DEPS02_DEL");
  按理来说,每种语言都是这样写,如java
  jdbcTemplate.execute("begin transaction t_customer_monitorEmail");
  try{
  ......
  jdbcTemplate.execute("commit transaction t_customer_monitorEmail");
  }catch(Exception e){
  jdbcTemplate.execute("rollback transaction t_customer_monitorEmail");
  }
  Hibernate方式:
  // Non-managed environment>
  Session sess = factory.openSession();
  Transaction tx = null;
  try {
  tx = sess.beginTransaction();
  // do some work
  ...
  tx.commit();
  }
  catch (RuntimeException e) {
  if (tx != null) tx.rollback();
  throw e; // or display error message
  }
  finally {
  sess.close();
  }

页: [1]
查看完整版本: PHP java MySQL 与 MsSQL 中的事务