/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import DataEntryBean.MicroFileAccountDetBean;
import LoginDb.DbHandler;
import java.io.File;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.jdbc.OracleTypes;

/**
 *
 * @author 981898
 */
public class MicroFileProcessingDao {

    public ArrayList<MicroFileAccountDetBean> getAccountDetails(String pacsId, String agentId) {

        ArrayList<MicroFileAccountDetBean> accountDetailsForPacs = new ArrayList<MicroFileAccountDetBean>();
        Connection con = null;
        StringBuilder accountGetQuery = null;
       // String prodCode1 = "3001";
        //String prodCode2 = "1101";
        ResultSet rs = null;
        PreparedStatement ps = null;
        MicroFileAccountDetBean accountDetails = null;
        String accountName = null;
        String todayAsString = new SimpleDateFormat("ddMMyyyy").format(new Date(System.currentTimeMillis()));
        try {
            con = DbHandler.getDBConnection();
          
//accountGetQuery = new StringBuilder().append(" select da.key_1 , da.avail_bal ,nvl(to_char(da.mat_dt, 'ddmmyyyy'),'NA') as mat_dt,to_char(da.acct_open_dt,'ddmmyyyy') as open_dt, dp.prod_name, kh.first_name,kh.middle_name,").append("kh.last_name,kh.address_1 , kh.address_2 , kh.address_3   from ").append("dep_account da ,dep_product dp , kyc_hdr kh where kh.cif_no = da.customer_no and  da.dep_prod_id=dp.id and ").append("da.pacs_id= ?")//.append(pacsId)
  //                .append(" and dp.prod_code in( ? ,?) ")//.append(prodCode)
    //                .append(" and dp.int_cat like '2%' ").append("and da.curr_status='O'");

accountGetQuery = new StringBuilder(" select da.key_1 , da.avail_bal ,to_char(da.mat_dt, 'ddmmyyyy') as mat_dt,to_char(da.acct_open_dt,'ddmmyyyy') as open_dt, dp.prod_name, translate(kh.first_name, chr(10) || chr(13) || chr(09), ' ') first_name, translate(kh.middle_name, chr(10) || chr(13) || chr(09), ' ') middle_name, translate(kh.last_name, chr(10) || chr(13) || chr(09), ' ') last_name, translate(kh.address_1, chr(10) || chr(13) || chr(09), ' ') address_1, translate(kh.address_2, chr(10) || chr(13) || chr(09), ' ') address_2, translate(kh.address_3, chr(10) || chr(13) || chr(09), ' ') address_3, translate(kh.guardian_name, chr(10) || chr(13) || chr(09), ' ') guardian_name from dep_account da ,dep_product dp , kyc_hdr kh, dds_agent_acct di where kh.cif_no = da.customer_no and  da.dep_prod_id=dp.id and da.pacs_id= ? and dp.prod_code in ('3001','1101') and dp.int_cat like '2%' and da.key_1=di.DDS_ACCT and di.pacs_id=di.pacs_id and di.agent_id= ? and da.curr_status='O'");

            ps = con.prepareStatement(accountGetQuery.toString());
            ps.setString(1, pacsId);
            ps.setString(2, agentId);
            //ps.setString(3, prodCode2);
          //  rs = ps.executeQuery();
            System.out.println(rs);
            while (rs.next()) {

                accountDetails = new MicroFileAccountDetBean();
                accountDetails.setAccountCode(rs.getString("key_1"));
                accountDetails.setAdd1(rs.getString("address_1") != null ? rs.getString("address_1") : "NA");
                accountDetails.setAdd2(rs.getString("address_2") != null ? rs.getString("address_2") : "NA");
                accountDetails.setAdd3(rs.getString("address_3") != null ? rs.getString("address_3") : "NA");
                accountDetails.setProdName(rs.getString("prod_name") != null ? rs.getString("prod_name") : "NA");
                accountDetails.setProdType("DEPOSIT");
                accountDetails.setAvailBal(rs.getDouble("avail_bal") != 0 ? rs.getDouble("avail_bal") : 0);

                accountName = null;
                accountName = ((rs.getString("first_name") != null) ? rs.getString("first_name").trim() : "") + " "
                        + ((rs.getString("middle_name") != null) ? rs.getString("middle_name").trim() : "") + " "
                        + ((rs.getString("last_name") != null) ? rs.getString("last_name").trim() : "NA");

                accountDetails.setAccountName(accountName);
                accountDetails.setAccntMaturityDate(rs.getString("mat_dt") != null ? rs.getString("mat_dt") : todayAsString);
                accountDetails.setAccntOpenDate(rs.getString("open_dt") != null ? rs.getString("open_dt") : todayAsString);
                accountDetails.setGuardianName(rs.getString("guardian_name") != null ? rs.getString("guardian_name") : "NA");
                accountDetailsForPacs.add(accountDetails);
            }
        } catch (Exception e) {
           // e.printStackTrace();
            System.out.println("Exception occured fetching dept details for pacs :" + pacsId);
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during connection close.");
            }
        }
        return accountDetailsForPacs;
    }

    public int insertIntoHandbillTemp(ArrayList<MicroFileAccountDetBean> accountDetailsList, String pacsId, String tellerId) {
        Connection con = null;
        StringBuilder accountInsertquery = null;
        PreparedStatement ps = null;
        int res = 0;
        int procRes = 0;
        CallableStatement proc = null;
        try {
            
           // con = DbHandler.getDBConnection();
            for (MicroFileAccountDetBean accountDetail : accountDetailsList) {
                try {

                    con = DbHandler.getDBConnection();
                    accountInsertquery = new StringBuilder("INSERT INTO handbill_temp_bkp  (OLD_ACCT_NO,CUST_NAME,END_BAL,PROSD_FLAG,PACS_ID,CRT_DATE,DR_TOTAL,CR_TOTAL,STATUS,TELLER_ID) values (?,?,?,?,?,trunc(sysdate),?,?,?,?)");


                    ps = con.prepareStatement(accountInsertquery.toString());

                    ps.setString(1, accountDetail.getAccountCode());
                    ps.setString(2, accountDetail.getAccountName());
                    ps.setDouble(3, accountDetail.getAvailBal());
                    ps.setString(4, "N");
                    ps.setString(5, pacsId);
                    ps.setDouble(6, accountDetail.getDrTotal());//added 29062018 rajdip
                    ps.setDouble(7, accountDetail.getCrTotal());//added 29062018 rajdip
                    ps.setString(8, "PENDING");//added 04072018 rajdip
                    ps.setString(9, tellerId);//added 04072018 rajdip

                    res = res + ps.executeUpdate();

                    ps = null;
                    accountInsertquery = null;                    
                    con.close();

                } catch (Exception e) {
                   // e.printStackTrace();
                   System.out.println("Error occurred during processing.");
                } finally {
                    if(con!=null) {
                        con.close();
                    }
                }
            }

            if (res != 0) {
                synchronized (this) {

                    con = DbHandler.getDBConnection();
                    proc = con.prepareCall("{ call handbill_pacs(?,?,?) }");
                    proc.setString(1, pacsId);
                    proc.setString(2, tellerId);
                    proc.registerOutParameter(3, OracleTypes.VARCHAR);

                    proc.executeUpdate();

                  //  procRes = proc.getInt(3);//error message from dds procedure
                    con.close();
                }
            }

        } catch (Exception e) {
           // e.printStackTrace();
            procRes = 0;
            System.out.println("Exception occured inserting  details in handBill_temp for pacs :" + pacsId);
        } finally {
            try {

                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during connection close.");
            }
        }
        return procRes;
    }

    public String insertIntoBulkFileDetails(ArrayList<MicroFileAccountDetBean> accountDetailsList, String pacsId, String tellerId, String filePath) {
        Connection con = null;
        StringBuilder accountInsertquery = null;
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;
        int res = 0;
        String procRes = null;
        CallableStatement proc = null;
        String fileId = null;
        try {
            try {

                con = DbHandler.getDBConnection();
                StringBuilder fileIdQry = new StringBuilder("select FILE_NAME_SEQ.NEXTVAL  from dual");
                ps = con.prepareStatement(fileIdQry.toString());
                synchronized (this) {
                    ResultSet rs = ps.executeQuery();
                    while (rs.next()) {
                        fileId = rs.getString(1);
                    }
                }
                ps = null;
                File bulkFile = new File(filePath);

                accountInsertquery = new StringBuilder("INSERT INTO BULK_FILES_DETAILS  (PACS_ID,TELLER_ID,FILE_NAME,POST_DATE,POST_TIME,STATUS,NO_OF_ROWS,FILE_ID ) values (?,?,?,trunc(sysdate), to_date(to_char(SYSTIMESTAMP, 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),?,?,? )");


                ps = con.prepareStatement(accountInsertquery.toString());

                ps.setString(1, pacsId);
                ps.setString(2, tellerId);
                ps.setString(3, bulkFile.getName().split(".csv")[0] + ".csv");//filename
                ps.setString(4, "PENDING");
                ps.setInt(5, accountDetailsList.size());
                ps.setString(6, fileId);

                res = ps.executeUpdate();

                ps = null;
                accountInsertquery = null;
               // con.close();


            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during processing.");
            
            } finally {
                try {
                    con.close();
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            }

        try {
           // con = DbHandler.getDBConnection();
            
            if (res != 0) {
                res = 0;
                for (MicroFileAccountDetBean accountDetail : accountDetailsList) {
                    try {

                        con = DbHandler.getDBConnection();

                        accountInsertquery = new StringBuilder("INSERT INTO BULK_TXN_DETAILS  (FILE_ID,PACS_ID,FROM_ACCT,TO_ACCT,TXN_AMT,TXN_TYP,NARATION,COL_ID,STATUS,TXN_DATE ) values (?,?,?,?,?,?,?,COL_ID_SEQ.NEXTVAL,?,trunc(sysdate) )");


                        ps = con.prepareStatement(accountInsertquery.toString());

                        ps.setString(1, fileId);
                        ps.setString(2, pacsId);
                        ps.setString(3, accountDetail.getFromAccBulk());
                        ps.setString(4, accountDetail.getToAccBulk());
                        ps.setDouble(5, accountDetail.getCrTotal());
                        ps.setString(6, accountDetail.getTxnType());
                        ps.setString(7, accountDetail.getMessage());
                        ps.setString(8, "PENDING");


                        res = res + ps.executeUpdate();

                        ps = null;
                        accountInsertquery = null;
                        con.close();

                    } catch (Exception e) {
                       // e.printStackTrace();
                        System.out.println("Error occurred during processing.");
                        res = 0;
//                        if (con != null) {
//                            con.close();
//                        }
                        //reverting if one insert failed
                        con = DbHandler.getDBConnection();
                        StringBuilder fileIdQry = new StringBuilder("update BULK_TXN_DETAILS set status = 'FAILED' where FILE_ID = ? and PACS_ID =?");
                        ps = con.prepareStatement(fileIdQry.toString());
                        ps.setString(1, fileId);
			ps.setString(2, pacsId);
                        int deleres = ps.executeUpdate();
			StringBuilder fileIdQry2 = new StringBuilder("update BULK_FILE_DETAILS set status = 'FAILED' where FILE_ID = ? and PACS_ID =?");
                        ps2 = con.prepareStatement(fileIdQry2.toString());
                        ps2.setString(1, fileId);
			ps2.setString(2, pacsId);
			int update = ps2.executeUpdate();
                        procRes = "Error in file format. Please check the file again.";
                        con.close();
                        break;
                    
                    } finally { 
                    System.out.println("Processing done."); 
                }
                }
            }

            if (res != 0) {
                synchronized (this) {

                    con = DbHandler.getDBConnection();
                    proc = con.prepareCall("{ call operations1.POST_BULK_TXN(?,?,?,?,?) }");
                    proc.setString(1, pacsId);
                    proc.setString(2, tellerId);
                    proc.setString(3, fileId);
                    proc.registerOutParameter(4, OracleTypes.VARCHAR);
                    proc.registerOutParameter(5, OracleTypes.NUMBER);


                    proc.executeUpdate();

                  //  procRes = proc.getString(4);//error message from dds procedure
                    con.close();
                }
            }
        }  catch (Exception e) {
               System.out.println("Error occurred during processing.");
            
            } finally {
                try {
                    if (con != null) {
                    con.close();
                    }
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            }

        } catch (Exception e) {
           // e.printStackTrace();
            procRes = "error occured during process";
            System.out.println("Exception occured inserting  details in BULK_TXN_DETAILS for pacs :" + pacsId);
        } finally {            
               System.out.println("Processing done.");
            
            }
        return procRes;
    }

    public String insertIntoBulkFileDetailsAccountRenewal(ArrayList<MicroFileAccountDetBean> accountDetailsList, String pacsId, String tellerId, String filePath) {
        Connection con = null;
        StringBuilder accountInsertquery = null;
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;
        int res = 0;
        String procRes = null;
        CallableStatement proc = null;
        String fileId = null;
        try {
            try {

                con = DbHandler.getDBConnection();
                StringBuilder fileIdQry = new StringBuilder("select FILE_NAME_SEQ.NEXTVAL  from dual");
                ps = con.prepareStatement(fileIdQry.toString());
                synchronized (this) {
                    ResultSet rs = ps.executeQuery();
                    while (rs.next()) {
                        fileId = rs.getString(1);
                    }
                }
                ps = null;
                File bulkFile = new File(filePath);

                accountInsertquery = new StringBuilder("INSERT INTO bulk_kcc_renewal_files  (PACS_ID,TELLER_ID,FILE_NAME,POST_DATE,POST_TIME,STATUS,NO_OF_ROWS,FILE_ID ) values (?,?,?,trunc(sysdate), to_date(to_char(SYSTIMESTAMP, 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),?,?,? )");


                ps = con.prepareStatement(accountInsertquery.toString());

                ps.setString(1, pacsId);
                ps.setString(2, tellerId);
                ps.setString(3, bulkFile.getName().split(".csv")[0] + ".csv");//filename
                ps.setString(4, "PENDING");
                ps.setInt(5, accountDetailsList.size());
                ps.setString(6, fileId);

                res = ps.executeUpdate();

                ps = null;
                accountInsertquery = null;
               // con.close();

            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during processing.");
            } finally {
                try {
                    con.close();
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            }

        try {
           // con = DbHandler.getDBConnection();
            
            if (res != 0) {
                res = 0;
                for (MicroFileAccountDetBean accountDetail : accountDetailsList) {
                    try {

                        con = DbHandler.getDBConnection();
                        accountInsertquery = new StringBuilder("INSERT INTO BULK_KCC_RENEW_ACC  (FILE_ID,PACS_ID,KEY_1,SANCTION_LIMIT,STATUS,TXN_DATE,TXN_TIME,LIMIT_EXP_DATE,COL_ID ) values (?,?,?,?,?,to_date(to_char(SYSTIMESTAMP, 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),trunc(sysdate),?,COL_ID_SEQ.NEXTVAL )");

                        ps = con.prepareStatement(accountInsertquery.toString());

                        ps.setString(1, fileId);
                        ps.setString(2, pacsId);
                        ps.setString(3, accountDetail.getToAccBulk());
                        ps.setString(4, accountDetail.getLimit());
                        ps.setString(5, "PENDING");
                        ps.setString(6, accountDetail.getAccntMaturityDate());//limitExpiry date

                        res = res + ps.executeUpdate();

                        ps = null;
                        accountInsertquery = null;
                        con.close();

                    } catch (Exception e) {
                       // e.printStackTrace();
                        res = 0;                        
                        //reverting if one insert failed
                        con = DbHandler.getDBConnection();
                        StringBuilder fileIdQry = new StringBuilder("update BULK_KCC_RENEW_ACC set status = 'FAILED' where FILE_ID = ? and PACS_ID =?");
                        ps = con.prepareStatement(fileIdQry.toString());
                        ps.setString(1, fileId);
			ps.setString(2, pacsId);
                        int deleres = ps.executeUpdate();
			StringBuilder fileIdQry2 = new StringBuilder("update BULK_KCC_RENEWAL_FILES set status = 'FAILED' where FILE_ID = ? and PACS_ID =?");
                        ps2 = con.prepareStatement(fileIdQry2.toString());
                        ps2.setString(1, fileId);
                        ps2.setString(2, pacsId);
                        int update = ps2.executeUpdate();
                        procRes = "Error in file format. Please check the file again.";
                        con.close();
                        break;
                    
                    } finally { 
                    System.out.println("Processing done."); 
                }
                }
            }

            if (res != 0) {
                synchronized (this) {

                    con = DbHandler.getDBConnection();
                    proc = con.prepareCall("{ call operations1.POST_KCC_RENEWAL(?,?,?,?,?) }");
                    proc.setString(1, pacsId);
                    proc.setString(2, tellerId);
                    proc.setString(3, fileId);
                    proc.registerOutParameter(4, OracleTypes.VARCHAR);
                    proc.registerOutParameter(5, OracleTypes.NUMBER);

                    proc.executeUpdate();

                   // procRes = proc.getString(4);//error message from dds procedure
                    con.close();

                }
            }
        } catch (Exception e) {
            System.out.println("Error occured during processing.");
        } finally {
                try {
                    if (con != null) {
                    con.close();
                    }
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            }                    

        } catch (Exception e) {
           // e.printStackTrace();
            procRes = "error occured during process";
            System.out.println("Exception occured inserting  details in handBill_temp for pacs :" + pacsId);
        } finally {            
               System.out.println("Processing done.");            
            }
        return procRes;
    }

    public String insertIntoBankPostKCCRenewal(ArrayList<MicroFileAccountDetBean> accountDetailsList, String pacsId, String tellerId, String filePath) {
        Connection con = null;
        StringBuilder accountInsertquery = null;
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;
        int res = 0;
        String procRes = null;
        CallableStatement proc = null;
        String fileId = null;
        try {
            try {

                con = DbHandler.getDBConnection();
                StringBuilder fileIdQry = new StringBuilder("select FILE_NAME_SEQ.NEXTVAL  from dual");
                ps = con.prepareStatement(fileIdQry.toString());
                synchronized (this) {
                    ResultSet rs = ps.executeQuery();
                    while (rs.next()) {
                        fileId = rs.getString(1);
                    }
                }
                ps = null;
                File bulkFile = new File(filePath);

                accountInsertquery = new StringBuilder("INSERT INTO bulk_kcc_renewal_files  (PACS_ID,TELLER_ID,FILE_NAME,POST_DATE,POST_TIME,STATUS,NO_OF_ROWS,FILE_ID ) values (?,?,?,trunc(sysdate), to_date(to_char(SYSTIMESTAMP, 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),?,?,? )");


                ps = con.prepareStatement(accountInsertquery.toString());

                ps.setString(1, pacsId);
                ps.setString(2, tellerId);
                ps.setString(3, bulkFile.getName().split(".csv")[0] + ".csv");//filename
                ps.setString(4, "PENDING");
                ps.setInt(5, accountDetailsList.size());
                ps.setString(6, fileId);

                res = ps.executeUpdate();

                ps = null;
                accountInsertquery = null;
               // con.close();


            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during processing.");
            
            } finally { 
                try {
                    if (con != null) {
                    con.close();
                    }
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            }

            try {
               // con = DbHandler.getDBConnection();
            
            if (res != 0) {
                res = 0;
                for (MicroFileAccountDetBean accountDetail : accountDetailsList) {
                    try {

                        con = DbHandler.getDBConnection();

                        accountInsertquery = new StringBuilder("INSERT INTO BULK_KCC_RENEW_ACC  (FILE_ID,PACS_ID,KEY_1,SANCTION_LIMIT,STATUS,TXN_DATE,TXN_TIME,LIMIT_EXP_DATE,COL_ID ) values (?,?,?,?,?,to_date(to_char(SYSTIMESTAMP, 'DD-MON-RRHH24:MI:SS'),'DD-MON-RRHH24:MI:SS'),trunc(sysdate),?,COL_ID_SEQ.NEXTVAL )");


                        ps = con.prepareStatement(accountInsertquery.toString());

                        ps.setString(1, fileId);
                        ps.setString(2, pacsId);
                        ps.setString(3, accountDetail.getToAccBulk());
                        ps.setString(4, accountDetail.getLimit());
                        ps.setString(5, "PENDING");
                        ps.setString(6, accountDetail.getAccntMaturityDate());//limitExpiry date


                        res = res + ps.executeUpdate();

                        ps = null;
                        accountInsertquery = null;
                        con.close();


                    } catch (Exception e) {
                       // e.printStackTrace();
                        res = 0;                        
                        //reverting if one insert failed
                        con = DbHandler.getDBConnection();
                        StringBuilder fileIdQry = new StringBuilder("update BULK_KCC_RENEW_ACC set status = 'FAILED' where FILE_ID = ?");
                        ps = con.prepareStatement(fileIdQry.toString());
                        ps.setString(1, fileId);
                        int deleres = ps.executeUpdate();
			StringBuilder fileIdQry2 = new StringBuilder("update BULK_KCC_RENEWAL_FILES set status = 'FAILED' where FILE_ID = ?");
                        ps2 = con.prepareStatement(fileIdQry2.toString());
                        ps2.setString(1, fileId);
			int update = ps2.executeUpdate();
                        procRes = "Error in file format. Please check the file again.";
                        con.close();
                        break;
                    } finally {
                        System.out.println("Processing done.");
                    }
                }
            }

            if (res != 0) {
                synchronized (this) {

                    con = DbHandler.getDBConnection();
                    proc = con.prepareCall("{ call operations2.BANK_POST_KCC_RENEWAL(?,?,?,?,?) }");
                    proc.setString(1, pacsId);
                    proc.setString(2, tellerId);
                    proc.setString(3, fileId);
                    proc.registerOutParameter(4, OracleTypes.VARCHAR);
                    proc.registerOutParameter(5, OracleTypes.NUMBER);


                    proc.executeUpdate();

                   // procRes = proc.getString(4);//error message from dds procedure
                    con.close();
                }
            } 
        } catch (Exception e) {
            System.out.println("Error occured during processing.");
        } finally {
                try {
                    if (con != null) {
                    con.close();
                    }
                } catch (Exception e) {
                    System.out.println("Error occured during connection close.");
                }
            } 

        } catch (Exception e) {
           // e.printStackTrace();
            procRes = "error occured during process";
            System.out.println("Exception occured inserting  details in handBill_temp for pacs :" + pacsId);
        } finally {            
               System.out.println("Processing done.");
            }
        
        return procRes;
    }

    public String insertBulkAccMap(List<String> accntdetailsList, String pacsId, String tellerId) {

        Connection con = null;
        PreparedStatement ps = null;
        int i = 0;
        String accNo[] = null;
        CallableStatement proc = null;
        String outMsg = "";

        try {
            con = DbHandler.getDBConnection();
            //i = accntdetailsList.size();

            try {
                while (i <= accntdetailsList.size() - 1) {

                    accNo = accntdetailsList.get(i).split("\\:");
                    ps = con.prepareStatement("insert into bulk_acct_map (pacs_id, key_1, cbs_acct, teller_id, map_dt, map_tym, status, id_typ, id_no) " +
                            " values (?,?,?,?,(select system_date from system_date),to_char(SYSTIMESTAMP, 'DD-MON-RRHH12:MI:SS'),'PENDING','','')");

                    ps.setString(1, pacsId);
                    ps.setString(2, accNo[0]);
                    ps.setString(3, accNo[1]);
                    ps.setString(4, tellerId);

                    ps.executeQuery();
                   // con.commit();
                    i = i + 1;

                }
            } catch (SQLException ex) {
               // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, ex);
                try {
                    if (ps != null) {
                        ps.close();
                    }                    
                } catch (SQLException ep) {
                   // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, ep);
                   System.out.println("Error occurred during processing.");
                } catch (Exception e) {
                   // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, e);
                   System.out.println("Error occurred during processing.");
                }

               // return "SQL error in inserting bulk_acct_map";
            } finally {
                System.out.println("SQL error in inserting bulk_acct_map.");
            }

            try {
                proc = con.prepareCall("{ call operations1.BULK_ACCT_MAPPING(?,?,?,?) }");

                proc.setString(1, pacsId);
                proc.setString(2, tellerId);
                proc.registerOutParameter(3, java.sql.Types.VARCHAR);
                proc.registerOutParameter(4, OracleTypes.NUMBER);

                proc.executeUpdate();

               // outMsg = proc.getString(3);
               // con.commit();
            } catch (SQLException ex) {
               // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, ex);
               // ex.printStackTrace();
               System.out.println("Error occurred during processing.");
                try {
                    if (proc != null) {
                    proc.close();
                    }                    

                } catch (Exception e) {
                   // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, e);
                   System.out.println("Error occurred during processing.");
                }

               // return "Procedure error in bulk account mapping";
            } finally {
                System.out.println("Procedure error in bulk account mapping.");
            }
        } catch (Exception e) {
           // e.printStackTrace();
           System.out.println("Error occurred during processing.");
        } finally {
            try {                
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
               // Logger.getLogger(MicroFileProcessingDao.class.getName()).log(Level.SEVERE, null, e);
               System.out.println("Error occurred during connection close.");
            }
        }
        return outMsg;
    }
}
