package day2;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import day1.JdbcUtil;
public class TransferTest {
/*
* update t_account set balance = 500 where accountname = 'suns';
* update t_account set balance = 14500 where accountname = 'xiaohei';
*
*/
public static void main(String args[]){
Connection conn = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
ResultSet rs = null;
try{
conn = JdbcUtil.getConnection();
conn.setAutoCommit(false);
String sql1 = " update t_account set balance = 200 where accountname = 'suns'";
String sql2 = " update t_accoun set balance = 14800 where accountname = 'xiaohei'";
pstmt1 = conn.prepareStatement(sql1);
pstmt2 = conn.prepareStatement(sql2);
pstmt1.executeUpdate();
pstmt2.executeUpdate();
conn.commit();
}catch(Exception e){
e.printStackTrace();
try{conn.rollback();}catch(Exception ee){}
}finally{
}
}
}