jdbc事物处理测试

table 是 innodb  非 myisam



package com.gyarmy.transcation;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;

import com.gyarmy.utils.JdbcUtils;

public class TestTranscation {
 
 @Test
 public void test1(){
 
 Connection conn=null;
 Statement stmt=null;
 try {
 conn = JdbcUtils.getConnection();
 conn.setAutoCommit(false);
 stmt = conn.createStatement();
 stmt.executeUpdate("update account set money = money-100 where name = 'aa'");
 int i = 1/0;
 stmt.executeUpdate("update account set money = money+100 where name = 'bb'");
 conn.commit();
 
 } catch (Exception e) {
 // TODO Auto-generated catch block
 try {
 conn.rollback();
 } catch (SQLException e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 }
 
 
 e.printStackTrace();
 
 } finally{
 JdbcUtils.releaseRes(null, stmt, conn);
 
 }
 
 
 
 }
 
 
}


原文链接: jdbc事物处理测试 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-73.html )

发表评论

0则评论给“jdbc事物处理测试”