public void transfer(String sourceAccount,String targetAccount,float money){

package com.tfy.itheima.service.impl;


import com.tfy.itheima.dao.impl.AccountDaoImpl;
import com.tfy.itheima.domain.Account;
import com.tfy.itheima.jdbc.util.DbcpUtil;


public class AccountServiceImpl {
public void transfer(String sourceAccount,String targetAccount,float money){
try{
DbcpUtil.startTransaction();
AccountDaoImpl dao=new AccountDaoImpl();
Account sAccount=dao.findAccount(sourceAccount);
Account tAccount=dao.findAccount(targetAccount);

sAccount.setMoney(sAccount.getMoney()-money);
tAccount.setMoney(tAccount.getMoney()+money);

dao.update(sAccount);
int i=1/0;
dao.update(tAccount);

}catch(Exception e){
e.printStackTrace();
DbcpUtil.rollback();
throw new RuntimeException(e);
}finally{
DbcpUtil.commit();
DbcpUtil.release();
}

}


}

你可能感兴趣的:(public void transfer(String sourceAccount,String targetAccount,float money){)