`
zengshaotao
  • 浏览: 788027 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

jdbc

    博客分类:
  • jdbc
 
阅读更多

package com.ccic.service.cash.time;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.rpc.ServiceException;

import org.apache.log4j.Logger;

import com.ccic.service.util.CommonFunction;
import com.ccic.service.util.DataSourceUtil;
import com.ccic.service.util.SQLFunction;
import com.ccic.service.util.SysParam;
import com.hundsun.dto.Account;
import com.hundsun.service.SyncAccountHttpBindingStub;
import com.hundsun.service.SyncAccountLocator;
import com.hundsun.service.SyncAccountPortType;

public class SynAccount {

 private static Logger logger = Logger.getLogger(SynAccount.class);

 // 将数据进行备份,同时删除中间表
 public static boolean bakData(Connection conn, PreparedStatement ps)
   throws SQLException {

  String sql = "insert into t_accounthis select * from t_accountmid";
  String deleteSQL = "delete from t_accountmid";

  ps = conn.prepareStatement(sql);
  ps.executeUpdate();
  ps.close();
  ps = conn.prepareStatement(deleteSQL);
  ps.executeUpdate();
  ps.close();
  return true;
 }

 // 更新银行账号信息表为无效
 public static boolean updateInvalid(Connection conn, PreparedStatement ps)
   throws SQLException {

  String updateInvalid = "update t_bankaccount  set ACCOUNT_STATUS = '0'";
  ps = conn.prepareStatement(updateInvalid);
  int updateRow = ps.executeUpdate();
  ps.close();
  logger.info("更新银行账号信息表为无效的行数:" + updateRow);
  return true;
 }

 // 调用恒生webservice,获得响应体数据
 public static Account[] getAccountInfo() throws ServiceException,
   RemoteException {
  
  String endPointUrl = SysParam.getSysParam("synAccount");
  logger.info("资金账号同步服务地址:"+endPointUrl);
  
  SyncAccountLocator locator = new SyncAccountLocator();
  locator.setSyncAccountHttpPortEndpointAddress(endPointUrl);
  
  SyncAccountPortType service = locator.getSyncAccountHttpPort();
  Account accountArr[] = null;
  SyncAccountHttpBindingStub stub = (SyncAccountHttpBindingStub) service;
  stub.setTimeout(100000);
  String str[] = { "" };
  accountArr = stub.syncAcc(str, "0");

  return accountArr;
 }

 // 手工加入数据调试
 public static Account[] manu() {
  Account accountArr[] = new Account[2];
  Account a1 = new Account();
  Account a2 = new Account();

  a1.setACCOUNT_ID(1);
  a1.setACCOUNT_OTHER_CODE("001");
  a1.setACCOUNT_OTHER_FLAG(1);
  a1.setACCOUNT_STATUS(1);
  a1.setBANK_ACCOUNT("622001");
  a1.setBANK_ACCOUNT_CURRENCY("CNY");
  a1.setBANK_ACCOUNT_NAME("张一");
  a1.setBANK_ACCOUNT_TYPE("1");
  a1.setBANK_AREA_NAME("上海杨浦");
  a1.setBANK_CODE("001");
  a1.setBANK_DETAIL_CODE("000001");
  a1.setBANK_DETAIL_NAME("国顺路支行");
  a1.setBANK_LOCATIONS_NAME("中原路1022号");
  a1.setBANK_NAME("上海浦发银行");
  a1.setBANK_SAVE_TYPE(1);
  // a1.setCLOSE_DATE("");
  a1.setDirect_FLAG(0);
  a1.setDOOR_ID("1");
  a1.setENTITY_CODE("01");
  a1.setENTITY_NAME("01");
  a1.setIS_OPEN(1);
  // a1.setOPEN_DATE("");

  a2.setACCOUNT_ID(2);
  a2.setACCOUNT_OTHER_CODE("002");
  a2.setACCOUNT_OTHER_FLAG(2);
  a2.setACCOUNT_STATUS(0);
  a2.setBANK_ACCOUNT("622002");
  a2.setBANK_ACCOUNT_CURRENCY("CNY");
  a2.setBANK_ACCOUNT_NAME("张二");
  a2.setBANK_ACCOUNT_TYPE("2");
  a2.setBANK_AREA_NAME("上海杨浦");
  a2.setBANK_CODE("001");
  a2.setBANK_DETAIL_CODE("000001");
  a2.setBANK_DETAIL_NAME("国顺路支行");
  a2.setBANK_LOCATIONS_NAME("中原路1022号");
  a2.setBANK_NAME("上海浦发银行");
  a2.setBANK_SAVE_TYPE(2);
  a2.setDirect_FLAG(0);
  a2.setDOOR_ID("1");
  a2.setENTITY_CODE("02");
  a2.setENTITY_NAME("02");
  a2.setIS_OPEN(1);

  accountArr[0] = a1;
  accountArr[1] = a2;

  return accountArr;
 }

 // 将数据转换成Map,便于转换成insert语句,针对更新服务信息中间表T_ACCOUNTMID
 @SuppressWarnings("unchecked")
 public static List arrayToMapMid(Account accountArr[]) {

  List<Map> list = new ArrayList<Map>();
  logger.info("获得的服务端账号信息如下:");
  for (int i = 0; i < accountArr.length; i++) {
   Map m = new HashMap();
   Account account = new Account();
   account = accountArr[i];

   logger.info("账号ID号:" + account.getACCOUNT_ID() + ",银行账户号:"
     + account.getBANK_ACCOUNT());

   m.put("ACCOUNT_ID", "" + account.getACCOUNT_ID());
   m.put("ACCOUNT_STATUS", "" + account.getACCOUNT_STATUS());
   m.put("ACCOUNT_OTHER_FLAG", "" + account.getACCOUNT_OTHER_FLAG());
   m.put("ACCOUNT_OTHER_CODE", "" + account.getACCOUNT_OTHER_CODE());

   m.put("BANK_CODE", "" + account.getBANK_CODE());
   m.put("BANK_NAME", account.getBANK_NAME());
   m.put("BANK_AREA_NAME", account.getBANK_AREA_NAME());
   m.put("BANK_LOCATIONS_NAME", account.getBANK_LOCATIONS_NAME());
   m.put("BANK_ACCOUNT", account.getBANK_ACCOUNT());
   m.put("BANK_ACCOUNT_NAME", account.getBANK_ACCOUNT_NAME());
   m.put("BANK_ACCOUNT_CURRENCY", account.getBANK_ACCOUNT_CURRENCY());
   m.put("BANK_ACCOUNT_TYPE", "" + account.getBANK_ACCOUNT_TYPE());
   m.put("BANK_SAVE_TYPE", "" + account.getBANK_SAVE_TYPE());
   if ("".equals(account.getBANK_DETAIL_CODE())) {
    m.put("BANK_DETAIL_CODE", "无");
   } else {
    m.put("BANK_DETAIL_CODE", account.getBANK_DETAIL_CODE());
   }
   if ("".equals(account.getBANK_DETAIL_NAME())) {
    m.put("BANK_DETAIL_NAME", "无");
   } else {
    m.put("BANK_DETAIL_NAME", account.getBANK_DETAIL_NAME());
   }

   if("".equals(account.getCLOSE_DATE())||account.getCLOSE_DATE()==null){
    m.put("CLOSE_DATE","");
   }else{
    m.put("CLOSE_DATE",account.getCLOSE_DATE().getTime().toLocaleString());
   }
   
   if("".equals(account.getOPEN_DATE())||account.getOPEN_DATE()==null){
    m.put("OPEN_DATE","");
   }else{
    m.put("OPEN_DATE",account.getOPEN_DATE().getTime().toLocaleString());
   }
   
   
   m.put("DOORID", ""+account.getDOOR_ID());
   m.put("DIRECT_FLAG", "" + account.getDirect_FLAG());
   m.put("ENTITY_CODE", "" + account.getENTITY_CODE());
   m.put("ENTITY_NAME", "" + account.getENTITY_NAME());
   m.put("IS_OPEN", ""+account.getIS_OPEN());

   m.put("PROCESS_STATUS_2", "2");
   m.put("PROCESS_DATE_2", CommonFunction.getLocalTime14());
   m.put("PROCESS_MESSAGE_2", "");
   m.put("ROW_VERSION", "1");
   m.put("SYNCBANKFLAG", "0");
   m.put("SYNCBANKDESC", "");
   m.put("SYNCACCOUNTFLAG", "0");
   m.put("SYNCACCOUNTDESC", "");

   list.add(m);
  }
  return list;
 }

 // 将数据转换成Map,便于转换成update语句,针对银行账号业务表T_BANKACCOUNT
 @SuppressWarnings({ "rawtypes", "unchecked" })
 public static List arrayToMapBank(Account accountArr[]) {

  List<Map> list = new ArrayList<Map>();

  for (int i = 0; i < accountArr.length; i++) {

   Account account = new Account();
   account = accountArr[i];
   Map m = new HashMap();
   m.put("ACCOUNT_ID", "" + account.getACCOUNT_ID());
   m.put("ACCOUNT_STATUS", "1");
   m.put("ACCOUNT_OTHER_FLAG", "" + account.getACCOUNT_OTHER_FLAG());
   m.put("ACCOUNT_OTHER_CODE", "" + account.getACCOUNT_OTHER_CODE());

   m.put("BANK_CODE", account.getBANK_CODE());
   m.put("BANK_NAME", account.getBANK_NAME());
   m.put("BANK_AREA_NAME", account.getBANK_AREA_NAME());
   m.put("BANK_LOCATIONS_NAME", account.getBANK_LOCATIONS_NAME());
   m.put("BANK_ACCOUNT", account.getBANK_ACCOUNT());
   m.put("BANK_ACCOUNT_NAME", account.getBANK_ACCOUNT_NAME());
   m.put("BANK_ACCOUNT_CURRENCY", account.getBANK_ACCOUNT_CURRENCY());
   m.put("BANK_ACCOUNT_TYPE", "" + account.getBANK_ACCOUNT_TYPE());
   m.put("BANK_SAVE_TYPE", "" + account.getBANK_SAVE_TYPE());

   if ("".equals(account.getBANK_DETAIL_CODE())) {
    m.put("BANK_DETAIL_CODE", "无");
   } else {
    m.put("BANK_DETAIL_CODE", "" + account.getBANK_DETAIL_CODE());
   }
   if ("".equals(account.getBANK_DETAIL_NAME())) {
    m.put("BANK_DETAIL_NAME", "无");
   } else {
    m.put("BANK_DETAIL_NAME", "" + account.getBANK_DETAIL_NAME());
   }

   if("".equals(account.getCLOSE_DATE())||account.getCLOSE_DATE()==null){
    m.put("CLOSE_DATE","");
   }else{
    m.put("CLOSE_DATE",account.getCLOSE_DATE().getTime().toLocaleString());
   }
   
   if("".equals(account.getOPEN_DATE())||account.getOPEN_DATE()==null){
    m.put("OPEN_DATE","");
   }else{
    m.put("OPEN_DATE",account.getOPEN_DATE().getTime().toLocaleString());
   }

   m.put("DOORID", "" + account.getDOOR_ID());
   m.put("DIRECT_FLAG", "" + account.getDirect_FLAG());

   m.put("ENTITY_CODE", account.getENTITY_CODE());
   m.put("ENTITY_NAME", account.getENTITY_NAME());

   m.put("IS_OPEN", "" + account.getIS_OPEN());

   m.put("TUPDTM", CommonFunction.getLocalTime14());
   m.put("TCRTTM", CommonFunction.getLocalTime14());
   m.put("SYN_PROCESS_STATUS", "0");
   m.put("SYN_PROCESS_INFO", "");

   list.add(m);
  }
  return list;
 }

 // 获得insert语句数组
 public static String[] getInsertSQLArr(String tableName, List<Map> list) {

  String insertSQLArr[] = new String[list.size()];
  for (int i = 0; i < list.size(); i++) {
   Map map = new HashMap();
   map = list.get(i);
   String insertSQL = SQLFunction.insertSQLSplice(tableName, map);
   insertSQLArr[i] = insertSQL;
  }
  return insertSQLArr;
 }

 // 批量插入到中间表
 public static void exeBatch(Connection conn, Statement st,
   PreparedStatement ps, String[] insertSQL) throws SQLException {

  try {

   st = conn.createStatement();
   for (int i = 0; i < insertSQL.length; i++) {
    st.addBatch(insertSQL[i]);
   }
   st.executeBatch();
   st.clearBatch();
   st.close();
  } catch (SQLException e) {
   e.printStackTrace();
   throw e;
  }

 }

 // 格式化时间
 public static java.util.Calendar format(Date date) {

  Calendar calendar = Calendar.getInstance();
  calendar.setTime(date);
  return calendar;
 }

 // 往中间任务表插入从服务端接收过来的数据
 public static boolean insertAccMid(Connection conn, PreparedStatement ps,
   Account[] accountArr) throws SQLException {

  String insertCol = "insert into t_accountmid "
    + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
    + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

  ps = conn.prepareStatement(insertCol);
  
  logger.info("获得的服务端账号信息如下:");

  for (int i = 0; i < accountArr.length; i++) {

   Account account = accountArr[i];
   
   logger.info("账号ID号:" + account.getACCOUNT_ID() + ",银行账户号:"
     + account.getBANK_ACCOUNT());
   
   ps.setString(1, "" + account.getACCOUNT_ID());
   ps.setString(2, "" + account.getENTITY_CODE());
   ps.setString(3, "" + account.getENTITY_NAME());
   ps.setString(4, "" + account.getBANK_CODE());
   ps.setString(5, "" + account.getBANK_NAME());
   ps.setString(6, "" + account.getBANK_AREA_NAME());
   ps.setString(7, "" + account.getBANK_LOCATIONS_NAME());
   ps.setString(8, "" + account.getBANK_ACCOUNT());
   ps.setString(9, "" + account.getBANK_ACCOUNT_NAME());
   ps.setString(10, "" + account.getBANK_ACCOUNT_CURRENCY());
   ps.setString(11, "" + account.getBANK_ACCOUNT_TYPE());
   ps.setString(12, "" + account.getBANK_SAVE_TYPE());
   
   if("".equals(account.getOPEN_DATE())||account.getOPEN_DATE()==null){
    ps.setString(13, "");
   }else{
    ps.setString(13, account.getOPEN_DATE().getTime().toLocaleString());
   }
   
   if("".equals(account.getCLOSE_DATE())||account.getCLOSE_DATE()==null){
    ps.setString(14, "");
   }else{
    ps.setString(14, account.getCLOSE_DATE().getTime().toLocaleString());
   }

   ps.setString(15, "" + account.getACCOUNT_STATUS());
   // 新增账户
   ps.setString(16, "");
   
   if("".equals(account.getBANK_DETAIL_CODE())||account.getBANK_DETAIL_CODE()==null){
    ps.setString(17, "无");
   }else{
    ps.setString(17,""+account.getBANK_DETAIL_CODE());
   }
   
   ps.setString(18, "" + account.getDirect_FLAG());
   ps.setString(19, "" + account.getACCOUNT_OTHER_FLAG());
   ps.setString(20, "" + account.getACCOUNT_OTHER_CODE());
   //PROCESS_STATUS_2
   ps.setString(21, "2");
   //PROCESS_DATE_2
   ps.setString(22, CommonFunction.getLocalTime14());
   //PROCESS_MESSAGE_2
   ps.setString(23, "");
   //CREATE_BY
   ps.setString(24, "");
   //ROW_VERSION
   ps.setString(25, "1");
   //IS_OPEN
   ps.setString(26, "" + account.getIS_OPEN());
   //DOORID
   ps.setString(27, account.getDOOR_ID());
   //SYNCBANKFLAG
   ps.setString(28, "1");
   //SYNCBANKDESC
   ps.setString(29, "");
   //SYNCACCOUNTFLAG
   ps.setString(30, "1");
   //SYNCACCOUNTDESC
   ps.setString(31, "");
   //BANK_DETAIL_NAME
   
   if("".equals(account.getBANK_DETAIL_NAME())||account.getBANK_DETAIL_NAME()==null){
    ps.setString(32, "无");
   }else{
    ps.setString(32,""+account.getBANK_DETAIL_NAME());
   }

   ps.addBatch();
  }
  ps.executeBatch();
  ps.clearBatch();
  ps.close();
  return true;
 }
 
 // 往银行账户业务表插入从服务端接收过来的数据 2011-11-04
 public static boolean insertBankAcc(Connection conn, PreparedStatement ps,
   Account[] accountArr) throws SQLException {

  String insertCol = "insert into T_BANKACCOUNT "
    + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
    + "?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

  ps = conn.prepareStatement(insertCol);
  
//  logger.info("获得的服务端账号信息如下:");

  for (int i = 0; i < accountArr.length; i++) {

   Account account = accountArr[i];
   
//   logger.info("账号ID号:" + account.getACCOUNT_ID() + ",银行账户号:"
//     + account.getBANK_ACCOUNT());
   
   ps.setString(1, "" + account.getACCOUNT_ID());
   ps.setString(2, "" + account.getENTITY_CODE());
   ps.setString(3, "" + account.getENTITY_NAME());
   ps.setString(4, "" + account.getBANK_CODE());
   ps.setString(5, "" + account.getBANK_NAME());
   ps.setString(6, "" + account.getBANK_AREA_NAME());
   ps.setString(7, "" + account.getBANK_LOCATIONS_NAME());
   ps.setString(8, "" + account.getBANK_ACCOUNT());
   ps.setString(9, "" + account.getBANK_ACCOUNT_NAME());
   ps.setString(10, "" + account.getBANK_ACCOUNT_CURRENCY());
   ps.setString(11, "" + account.getBANK_ACCOUNT_TYPE());
   ps.setString(12, "" + account.getBANK_SAVE_TYPE());
   
   if("".equals(account.getOPEN_DATE())||account.getOPEN_DATE()==null){
    ps.setString(13, "");
   }else{
    ps.setString(13, account.getOPEN_DATE().getTime().toLocaleString());
   }
   
   if("".equals(account.getCLOSE_DATE())||account.getCLOSE_DATE()==null){
    ps.setString(14, "");
   }else{
    ps.setString(14, account.getCLOSE_DATE().getTime().toLocaleString());
   }

   ps.setString(15, "1");
   // 新增账户
   ps.setString(16, "");
   
   if("".equals(account.getBANK_DETAIL_CODE())||account.getBANK_DETAIL_CODE()==null){
    ps.setString(17, "无");
   }else{
    ps.setString(17,""+account.getBANK_DETAIL_CODE());
   }
   
   ps.setString(18, "" + account.getDirect_FLAG());
   ps.setString(19, "" + account.getACCOUNT_OTHER_FLAG());
   ps.setString(20, "" + account.getACCOUNT_OTHER_CODE());
   //CREATE_BY
   ps.setString(21, "");
   //ROW_VERSION
   ps.setString(22, "1");
   //IS_OPEN
   ps.setString(23, "" + account.getIS_OPEN());
   //DOORID
   ps.setString(24, account.getDOOR_ID());
   
   ps.setString(25, CommonFunction.getLocalTime14());
   ps.setString(26, CommonFunction.getLocalTime14());
   ps.setString(27, "1");
   ps.setString(28, "");
   
   if("".equals(account.getBANK_DETAIL_NAME())||account.getBANK_DETAIL_NAME()==null){
    ps.setString(29, "无");
   }else{
    ps.setString(29,""+account.getBANK_DETAIL_NAME());
   }

   ps.addBatch();
  }
  ps.executeBatch();
  ps.clearBatch();
  ps.close();
  return true;
 }
 
 // 更新银行账号业务表
 public static boolean updateBankAcc(Connection conn, PreparedStatement ps,
   Account[] addAccountExtArr) throws SQLException {

  String colVal = "ACCOUNT_STATUS='1',ACCOUNT_OTHER_FLAG=?,ACCOUNT_OTHER_CODE=?,SYN_PROCESS_INFO=?,"
    + "SYN_PROCESS_STATUS=?,TUPDTM=?,ROW_VERSION=ROW_VERSION+1,OPEN_DATE=?,"
    + "IS_OPEN=?,DIRECT_FLAG=?,DOORID=?,CLOSE_DATE=?,BANK_DETAIL_NAME=?,"
    + "BANK_DETAIL_CODE=?,BANK_SAVE_TYPE=?,BANK_ACCOUNT_TYPE=?,BANK_ACCOUNT_CURRENCY=?,"
    + "BANK_ACCOUNT_NAME=?,BANK_ACCOUNT=?,BANK_LOCATIONS_NAME=?,"
    + "BANK_AREA_NAME=?,BANK_NAME=?,BANK_CODE=? ";

  String updateBankAccSql = "update t_bankaccount set " + colVal
    + "where ACCOUNT_ID =?";

  ps = conn.prepareStatement(updateBankAccSql);

  for (int i = 0; i < addAccountExtArr.length; i++) {

   Account account = addAccountExtArr[i];

   ps.setString(1, "" + account.getACCOUNT_OTHER_FLAG());
   ps.setString(2, account.getACCOUNT_OTHER_CODE());
   ps.setString(3, "");
   ps.setString(4, "1");
   ps.setString(5, CommonFunction.getLocalTime14());
   // ps.setDate(6,(Date)account.getOPEN_DATE().getTime());
   ps.setString(7, "" + account.getIS_OPEN());
   ps.setString(8, "" + account.getDirect_FLAG());
   ps.setString(9, account.getDOOR_ID());
   // ps.setString(10, account.getCLOSE_DATE());
   ps.setString(11, account.getBANK_DETAIL_NAME());
   ps.setString(12, account.getBANK_DETAIL_CODE());
   ps.setString(13, "" + account.getBANK_SAVE_TYPE());
   ps.setString(14, account.getBANK_ACCOUNT_TYPE());
   ps.setString(15, account.getBANK_ACCOUNT_CURRENCY());
   ps.setString(16, account.getBANK_ACCOUNT_NAME());
   ps.setString(17, account.getBANK_ACCOUNT());
   ps.setString(18, account.getBANK_LOCATIONS_NAME());
   ps.setString(19, account.getBANK_AREA_NAME());
   ps.setString(20, account.getBANK_NAME());
   ps.setString(21, account.getBANK_CODE());

   ps.addBatch();
  }

  if (addAccountExtArr.length > 0) {
   ps.executeBatch();
  }
  ps.close();
  return true;
 }

 // 银行和账号信息同步业务处理
 @SuppressWarnings("unchecked")
 public static boolean synBankAcc(Connection conn, PreparedStatement ps,
   Statement st, Account[] accountArr) throws Exception {

  // PreparedStatement是一个管道,多个执行语句可以共用一个
  // ResultSet是操作结果,随用随关
  boolean result = false;
  ResultSet rs = null;

  try {

   List<String> listInvalid = new ArrayList<String>();
   String sql = "select t1.account_id from t_bankaccount t1 "
     + "where not exists"
     + "(select account_id from t_accountmid t2 where t1.account_id=t2.account_id )"
     + " and ACCOUNT_STATUS = '1'";

   ps = conn.prepareStatement(sql);

   rs = ps.executeQuery();

   while (rs.next()) {
    listInvalid.add(rs.getString(1));
   }
   rs.close();
   ps.close();
   String inCond = SQLFunction.getInConditon(listInvalid);
   String updateInvalid = "update t_bankaccount set ACCOUNT_STATUS='0',TUPDTM=? " +
     "where account_id in"+ inCond;
   ps = conn.prepareStatement(updateInvalid);
   ps.setString(1, CommonFunction.getLocalTime14());
   
   int updateRow = ps.executeUpdate();
   ps.close();
   logger.info("此次同步有【" + updateRow + "】条数据被更新为无效");

   String deleteBankAcc = "delete from t_bankaccount where ACCOUNT_STATUS = '1'";
   ps = conn.prepareStatement(deleteBankAcc);
   int deleteRow = ps.executeUpdate();
   ps.close();
   if (deleteRow == 0) {
    logger.info("此次共有【" + accountArr.length + "】条数据被同步!");
   } else {
    logger.info("此次共有【" + deleteRow + "】条数据被同步!");
   }
   
//   List<Map> acclist = arrayToMapBank(accountArr);
//   String insertSQLArr[] = getInsertSQLArr("T_BANKACCOUNT", acclist);
//   exeBatch(conn, st, ps, insertSQLArr);
   
   insertBankAcc(conn,ps,accountArr);
  
   result = true;

  } catch (SQLException e) {
   result = false;
   e.printStackTrace();
   throw e;
  } catch (Exception e) {
   result = false;
   e.printStackTrace();
   throw e;
  }

  return result;
 }

 // 业务入口
 public static Object doTask() {

  Connection conn = null;
  PreparedStatement ps = null;
  // 用于批量插入
  Statement st = null;

  try {

   conn = DataSourceUtil.getConnection();
   // 手动开启事务
   conn.setAutoCommit(false);

   logger.info("*********************中间表数据备份到历史表t_accounthis处理开始***********************");
   // 定时程序开始后,将中间表数据导入到历史表里,然后删除中间表数据
   // 中间表结构与历史表完全相同,只是各个字段都可以为空
   bakData(conn, ps);
   logger.info("*********************中间表数据备份到历史表t_accounthis处理结束***********************");

   // 通过webservice得到账号的全量信息
   Account accountArr[] = getAccountInfo();
   
   logger.info("*********************批量插入服务端返回的数据到中间表处理开始***********************");
   insertAccMid(conn,ps,accountArr);
   logger.info("*********************批量插入服务端返回的数据到中间表处理结束***********************");

   logger.info("*********************银行账号信息同步业务处理开始***********************");
   // 银行账号信息同步业务处理
   synBankAcc(conn, ps, st, accountArr);
   logger.info("*********************银行账号信息同步业务处理结束***********************");

   conn.commit();
   conn.setAutoCommit(true);

  } catch (SQLException e) {
   e.printStackTrace();
   logger.info("", e);
   try {
    conn.rollback();
    conn.setAutoCommit(true);
   } catch (SQLException e1) {
    e1.printStackTrace();
   }
  } catch (ServiceException se) {
   se.printStackTrace();
   logger.info("", se);
   try {
    conn.rollback();
    conn.setAutoCommit(true);
   } catch (SQLException e1) {
    logger.info("", e1);
    e1.printStackTrace();
   }
  } catch (RemoteException re) {
   re.printStackTrace();
   logger.info("", re);
   try {
    conn.rollback();
    conn.setAutoCommit(true);
   } catch (SQLException e1) {
    logger.info("", e1);
    e1.printStackTrace();
   }
  } catch (Exception e) {
   e.printStackTrace();
   logger.info("", e);
   try {
    conn.rollback();
    conn.setAutoCommit(true);
   } catch (SQLException e1) {
    logger.info("", e1);
    e1.printStackTrace();
   }
  } finally {

   try {
    if (st != null) {
     st.close();
    }
    if(ps !=null){
     ps.close();
    }
    if (conn != null) {
     conn.setAutoCommit(true);
     conn.close();
    }
   } catch (SQLException e) {
    e.printStackTrace();
    logger.info("", e);
   }

  }
  return "success";
 }

 // 定时器入口
 public static void main(String args[]) {

  logger.info("***********************账号同步开始***********************");
  doTask();
  logger.info("***********************账号同步结束***********************");
 }
}

分享到:
评论

相关推荐

    JDBCDriver3.0.rar_jdbc driver 3.0_sql jdbc 3.0_sql server jdbc_s

    《深入理解JDBC Driver 3.0:聚焦SQL Server JDBC》 在IT行业中,数据库连接是应用程序与数据存储之间的桥梁,而JDBC(Java Database Connectivity)则是Java平台中用于访问数据库的标准API。JDBC Driver 3.0是针对...

    sqlserver驱动包 jdbc驱动 sqljdbc.jar和sqljdbc4.jar

    SQL Server驱动包是用于Java应用程序通过JDBC(Java Database Connectivity)接口与Microsoft SQL Server数据库进行交互的必备组件。本文将详细介绍这两个重要的驱动文件——sqljdbc.jar和sqljdbc4.jar,以及如何...

    sqljdbc和sqljdbc4 sqlserver最新驱动

    SQLJDBC和SQLJDBC4是Microsoft为Java应用程序提供的用于连接SQL Server数据库的驱动程序。这两个版本都是JDBC(Java Database Connectivity)驱动,允许Java开发者在应用程序中与SQL Server进行交互。下面将详细介绍...

    Spring Data JDBC与JDBC的区别

    Spring Data JDBC与JDBC是两种不同的数据库访问方式,它们在Java开发中有着广泛的应用。JDBC(Java Database Connectivity)是Java平台的标准API,用于与各种数据库进行交互。它提供了低级别的数据库操作,如建立...

    sap JDBC数据源配置

    ### SAP JDBC 数据源配置 #### 引言与目的 本文档旨在提供详细的步骤指南,用于在SAP NetWeaver 7.0 和 SAP Composite Environment (CE) 7.1 上配置 JDBC 数据源和系统。通过这些步骤,用户可以创建一个独立的数据...

    mysql jdbc 驱动 适用于5.6版本及以下数据库

    mysql jdbc 驱动 适用于5.6版本及以下数据库 mysql jdbc 驱动 适用于5.6版本及以下数据库 mysql jdbc 驱动 适用于5.6版本及以下数据库 mysql jdbc 驱动 适用于5.6版本及以下数据库 mysql jdbc 驱动 适用于5.6版本及...

    mysql jdbc 驱动 适用于5.7及以上版本数据库

    mysql jdbc 驱动 适用于5.7及以上版本数据库 mysql jdbc 驱动 适用于5.7及以上版本数据库 mysql jdbc 驱动 适用于5.7及以上版本数据库 mysql jdbc 驱动 适用于5.7及以上版本数据库 mysql jdbc 驱动 适用于5.7及以上...

    sqljdbc41、sqljdbc42的官方jar包

    在Java编程语言中,JDBC(Java Database Connectivity)是一个核心的API,用于连接Java应用程序与各种类型的数据库。这里我们关注的是两个特定版本的Microsoft SQL Server的JDBC驱动:sqljdbc41.jar和sqljdbc42.jar...

    Dm7JdbcDriver16.jar Dm7JdbcDriver17.jar Dm7JdbcDriver18.jar

    在给定的压缩包文件中,包含了三个不同版本的达梦JDBC驱动,分别是Dm7JdbcDriver16.jar、Dm7JdbcDriver17.jar和Dm7JdbcDriver18.jar。 1. **JDBC驱动介绍**: JDBC是Java中用于与各种数据库进行交互的标准接口,它...

    自学jdbc心得体会

    JDBC 基础知识点 JDBC(Java Database Connectivity)是一种Java标准的数据库连接API,它允许Java程序访问各种关系数据库。下面是JDBC的基础知识点: 一、JDBC原理概述 * JDBC是一套协议,由Sun定义的一组接口,...

    jdbc jdbc jdbc

    Java Database Connectivity(JDBC)是Java编程语言中用于与各种数据库进行交互的一种标准接口。它由Sun Microsystems(现为Oracle公司)开发并定义,作为Java平台的一部分,允许Java应用程序通过编写Java代码来访问...

    sql server2000 jdbc

    SQL Server 2000 JDBC 是Java编程语言与Microsoft SQL Server 2000数据库进行交互的一种重要方式。JDBC(Java Database Connectivity)是Java API,允许Java应用程序通过Java虚拟机(JVM)与各种数据库建立连接。在...

    Access_JDBC30

    标题 "Access_JDBC30" 暗示了这是一个与Microsoft Access数据库相关的Java JDBC驱动程序。JDBC(Java Database Connectivity)是Java编程语言中用于连接和操作数据库的标准接口。这个jar包,"Access_JDBC30.jar",...

    kingbaseV8 jdbc 驱动

    KingbaseV8 JDBC驱动是连接KingbaseV8数据库的重要组件,允许Java应用程序通过JDBC(Java Database Connectivity)接口与数据库进行交互。JDBC是Java语言中用来规范客户端程序如何访问数据库的应用程序接口,提供了...

    sqljdbc42.jar、sqljdbc41.jar 更新日期2017-12-21

    标题中的"sqljdbc42.jar、sqljdbc41.jar 更新日期2017-12-21"指的是Microsoft SQL Server的Java Database Connectivity (JDBC) 驱动的两个不同版本,它们分别对应于Java SE 7和Java SE 8的兼容性。JDBC驱动是Java...

    access的jdbc驱动

    Access的JDBC驱动是Java数据库连接(Java Database Connectivity, JDBC)的一种实现,它允许Java程序与Microsoft Access数据库进行交互。在JDK 1.8之后,Oracle公司不再默认提供对ODBC(Open Database Connectivity...

    sqljdbc4.jar, sqljdbc41.jar, sqljdbc42.jar三个包

    标题中的"sqljdbc4.jar, sqljdbc41.jar, sqljdbc42.jar"是指Microsoft SQL Server为Java应用程序提供的Java Database Connectivity (JDBC)驱动程序。这些JAR文件是数据库连接的关键,允许Java代码与SQL Server进行...

    sqljdbc 3.0及4.0

    `sqljdbc`是Microsoft提供的一个驱动程序,使得Java应用程序能够与SQL Server数据库进行交互。在这个场景中,我们关注的是`sqljdbc 3.0`和`4.0`版本,这两个版本都是专门为Java设计的,用于连接SQL Server 2000。 `...

    Windowssever 2016 连sqlsever的jar包 JDK1.7/1.8 sqljdbc41/sqljdbc42

    `sqljdbc41`和`sqljdbc42`是SQL Server特有的一套JDBC驱动,分别对应JDBC 4.1和JDBC 4.2标准,适用于JDK 7和JDK 8。 1. **JDBC 4.1 (sqljdbc41.jar)**:这个版本的驱动支持JDK 7,它引入了新的特性,如异步操作、...

Global site tag (gtag.js) - Google Analytics