?? tradebusiness.java
字號:
/*
* Created on 2005-7-25
*
*/
package banksystem.business;
/**
* @author 曲本盛
*
* TODO Struts 項目實踐
*/
import java.sql.*;
import javax.sql.*;
import banksystem.Constants;
import banksystem.GetCurrentTime;
import banksystem.PO.Trade;
import banksystem.exception.*;
public class TradeBusiness {
/**
* @param dataSource 數據源.
* @param trade 交易信息.
*/
public void trade(DataSource dataSource,Trade trade)throws TranferAccountNotExistException,BalanceNotEnoughException,AccountFreezedException,SQLException{
//該方法將會拋出在SQL服務器中定義的特定錯誤消息,由Delegate接收并處理為特定的Exception類
Connection con = null;
PreparedStatement stat = null;
try{
con = dataSource.getConnection();
stat = con.prepareStatement(Constants.SQL_TRADE_INSERT);
stat.setString(1,"");
stat.setString(2,trade.getAccountID());
stat.setString(3,trade.getTransferAccountID());
stat.setString(4,trade.getType());
stat.setDouble(5,trade.getMoney().doubleValue());
stat.setString(6,GetCurrentTime.getCurrentTime());
int rows = stat.executeUpdate();
if(rows==0){
throw new SQLException(Constants.INSERT_FAILED);
}
}
catch(SQLException e){
//按接收異常的錯誤號重拋特定異常
//System.out.println(e.getErrorCode());
//此處采取兩種方案一種是根據錯誤號重拋特定異常,二是將SQL的錯誤信息直接交給界面
if(e.getErrorCode()==Constants.ERRORCODE_ACCOUNT_NOT_EXIST){
throw new TranferAccountNotExistException(Constants.ERRORS_TRANFER_NOT_EXIST);
}
else if(e.getErrorCode()==Constants.ERRORCODE_BALANCE_NOT_ENOUGH){
throw new BalanceNotEnoughException(Constants.ERRORS_BALANCE_NOT_ENOUGH);
}
else if(e.getErrorCode()==Constants.ERRORCODE_ACCOUNT_FREEZED){
throw new AccountFreezedException(Constants.ERRORS_ACCOUNT_FREEZED);
}
else{
throw new SQLException(e.getMessage());
}
}
finally{
try{
if(con!=null){
con.close();
}
if(stat!=null){
stat.close();
}
}
catch(Exception e){
throw new SQLException(Constants.DATABASE_CLOSE_FAILED);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -