import com.hexin.wp.bean.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.hexin.jdbc.DBUtil;
/**
* 出账类,出通话大类费用
* @author Administrator
*
*/
public class InsertTotalMonth {
Statement stmt = null;
/**
* 批价好的数据,插入数据库
*/
public void insertMonthFee() {
String period;
String callingNO;
int phoneUserNO;
int callNO;
double total;
String periodMonth;
//建立数据库连接
DBUtil db = new DBUtil();
Connection conn = db.getConnection();
ArrayList<CallsSortBean> monthFeeList = new ArrayList<CallsSortBean>();
TotalMonthCalls tmc = new TotalMonthCalls();
//获得当前账期
period = tmc.getPeriod();
monthFeeList = tmc.getFee(period);
monthFeeList = tmc.setPhoneUser(monthFeeList);
try {
stmt = conn.createStatement();
} catch (SQLException e1) {
e1.printStackTrace();
}
for(int i=0; i<monthFeeList.size(); i++) {
callingNO = monthFeeList.get(i).getPhoneNumber();
phoneUserNO = monthFeeList.get(i).getPhoneUserNO();
//获得费用类型
callNO = monthFeeList.get(i).getFeeType();
//获得该费用类型的总金额
total = monthFeeList.get(i).getFeeToal();
//取到帐期
periodMonth = monthFeeList.get(i).getPeriodMonth();
String sql = "insert into CALL_FEE_MONTH values(
CALL_FEE_MONTH_SEQ.nextval,"+phoneUserNO+","
+periodMonth+","+callNO+","+total+","+callingNO+")";
String sql2 = "update CALL_DETAILS_FEE set IF_CZ=1 where CALLING_NO="+callingNO;
try {
if(conn != null) {
conn.setAutoCommit(false); //关闭事务自动提交
//执行插入操作
stmt.execute(sql);
//更新:将出账后的记录标示为1:已出账
stmt.executeUpdate(sql2);
conn.commit(); //手动提交事务
}
} catch (SQLException e) {
try {
conn.rollback(); //事务提交异常后回滚
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
continue;
} finally { //最终必须执行关闭数据库连接操作
try {
if(this.stmt != null) this.stmt.close();
if(conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]