Example usage for java.sql SQLException getStackTrace

List of usage examples for java.sql SQLException getStackTrace

Introduction

In this page you can find the example usage for java.sql SQLException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * If the result set contains the indicated column, extracts its short value and sets an attribute at the given element.
 * /*  ww w  .j av  a 2 s . c  o  m*/
 * @param xmlWriter  The xml writer to write to
 * @param attrName   The name of the attribute to write
 * @param result     The result set
 * @param columns    The columns in the result set
 * @param columnName The name of the column in the result set
 */
private void addShortAttribute(PrettyPrintingXmlWriter xmlWriter, String attrName, ResultSet result,
        Set columns, String columnName) throws SQLException {
    if (columns.contains(columnName)) {
        try {
            xmlWriter.writeAttribute(null, attrName, String.valueOf(result.getShort(columnName)));
        } catch (SQLException ex) {
            // A few databases do not comply with the jdbc spec and return a string (or null),
            // so lets try strings this just in case
            String value = result.getString(columnName);

            if (value != null) {
                try {
                    xmlWriter.writeAttribute(null, attrName, new Short(value).toString());
                } catch (NumberFormatException parseEx) {
                    log("Could not parse the value from result set column " + columnName + ":"
                            + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
        }
    }
}

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * If the result set contains the indicated column, extracts its boolean value and sets an attribute at the given element.
 * /*from   ww  w.  j av  a2s.  co  m*/
 * @param xmlWriter  The xml writer to write to
 * @param attrName   The name of the attribute to write
 * @param result     The result set
 * @param columns    The columns in the result set
 * @param columnName The name of the column in the result set
 */
private void addBooleanAttribute(PrettyPrintingXmlWriter xmlWriter, String attrName, ResultSet result,
        Set columns, String columnName) throws SQLException {
    if (columns.contains(columnName)) {
        try {
            xmlWriter.writeAttribute(null, attrName, String.valueOf(result.getBoolean(columnName)));
        } catch (SQLException ex) {
            // A few databases do not comply with the jdbc spec and return a string (or null),
            // so lets try strings this just in case
            String value = result.getString(columnName);

            if (value != null) {
                try {
                    xmlWriter.writeAttribute(null, attrName, new Boolean(value).toString());
                } catch (NumberFormatException parseEx) {
                    log("Could not parse the value from result set column " + columnName + ":"
                            + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
        }
    }
}

From source file:org.wsm.database.tools.util.FANConnectionManager.java

public Connection getConnection() throws DBConnectionFailedException, EmptyDataSourceException {
    Connection con = super.getConnection();
    if (con instanceof OracleConnection) {
        try {/*from  w w  w .j a v a2  s.  c o m*/
            log.debug("Registering Connection cache callback for connection " + con);
            ((OracleConnection) con).registerConnectionCacheCallback(new OracleConnectionCacheCallbackImpl(),
                    null, OracleConnection.ALL_CONNECTION_CALLBACKS);
            log.debug("Registration Done");
        } catch (SQLException e) {
            log.error("Error registering Connection cache callback. The reason is :");
            log.error(e.getStackTrace());
        }
    }
    return con;
}

From source file:org.wsm.database.tools.util.FANConnectionManager.java

public Connection getConnection(String keyName) throws DBConnectionFailedException, EmptyDataSourceException {
    Connection con = super.getConnection(keyName);
    if (con instanceof OracleConnection) {
        try {/*  www . j  ava  2 s .  co m*/
            log.debug("Registering Connection cache callback for connection " + con);
            ((OracleConnection) con).registerConnectionCacheCallback(new OracleConnectionCacheCallbackImpl(),
                    null, OracleConnection.ALL_CONNECTION_CALLBACKS);
            log.debug("Registration Done");
        } catch (SQLException e) {
            log.error("Error registering Connection cache callback. The reason is :");
            log.error(e.getStackTrace());
        }
    }
    return con;
}

From source file:rems.Program.java

private static boolean postIntoSuspnsAccnt(BigDecimal aeVal, BigDecimal crlVal, int orgID, boolean isspcl,
        String[] errmsg) {/*from  w  ww  .  j  a  v  a  2s. c o m*/
    try {
        int suspns_accnt = Global.get_Suspns_Accnt(orgID);
        int net_accnt = Global.get_Net_Income_Accnt(orgID);
        int ret_accnt = Global.get_Rtnd_Erngs_Accnt(orgID);

        if (suspns_accnt == -1) {
            errmsg[0] += "Please define a suspense Account First before imbalance can be Auto-Corrected!";
            return false;
        }
        long suspns_batch_id = -999999991;
        int funcCurrID = Global.getOrgFuncCurID(orgID);
        BigDecimal dffrnc = aeVal.subtract(crlVal);
        String incrsDcrs = "D";
        if (dffrnc.compareTo(BigDecimal.valueOf(0.00)) < 0) {
            incrsDcrs = "I";
        }
        BigDecimal imbalAmnt = dffrnc.abs();
        double netAmnt = (double) Global.dbtOrCrdtAccntMultiplier(suspns_accnt, incrsDcrs)
                * imbalAmnt.doubleValue();
        String dateStr = Global.getFrmtdDB_Date_time();
        if (!Global.isTransPrmttd(suspns_accnt, dateStr, netAmnt, errmsg)) {
            return false;
        }

        if (Global.dbtOrCrdtAccnt(suspns_accnt, incrsDcrs).equals("Debit")) {
            Global.createTransaction(suspns_accnt, "Correction of Imbalance as at " + dateStr,
                    imbalAmnt.doubleValue(), dateStr, funcCurrID, suspns_batch_id, 0.00, netAmnt,
                    imbalAmnt.doubleValue(), funcCurrID, imbalAmnt.doubleValue(), funcCurrID, (double) 1,
                    (double) 1, "D");
        } else {
            Global.createTransaction(suspns_accnt, "Correction of Imbalance as at " + dateStr, 0.00, dateStr,
                    funcCurrID, suspns_batch_id, imbalAmnt.doubleValue(), netAmnt, imbalAmnt.doubleValue(),
                    funcCurrID, imbalAmnt.doubleValue(), funcCurrID, (double) 1, (double) 1, "C");
        }

        ResultSet dtst = Global.get_Batch_Trns(suspns_batch_id);
        dtst.last();
        int dtstTtl = dtst.getRow();
        dtst.beforeFirst();

        for (int i = 0; i < dtstTtl; i++) {
            dtst.next();
            boolean hsBnUpdt = Global.hsTrnsUptdAcntBls(Long.parseLong(dtst.getString(1)), dtst.getString(7),
                    Integer.parseInt(dtst.getString(10)));
            if (hsBnUpdt == false) {
                double dbt1 = Double.parseDouble(dtst.getString(5));
                double crdt1 = Double.parseDouble(dtst.getString(6));
                double net1 = Double.parseDouble(dtst.getString(11));

                Global.postTransaction(Integer.parseInt(dtst.getString(10)), dbt1, crdt1, net1,
                        dtst.getString(7), Long.parseLong(dtst.getString(1)));
                Global.chngeTrnsStatus(Long.parseLong(dtst.getString(1)), "1");
            }
        }
        Program.reloadAcntChrtBals(suspns_batch_id, net_accnt);
        return true;
    } catch (SQLException ex) {
        errmsg[0] += ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace());
        return false;
    } catch (NumberFormatException ex) {
        errmsg[0] += ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace());
        return false;
    }
}

From source file:rems.Program.java

private static void postGLBatch(long glBatchID, String btchSrc, long msg_id, String log_tbl, String dateStr,
        int net_accnt, int funCurID) {
    try {/*from  www.  j a va  2  s  .  co m*/
        //String dateStr1 = Global.getFrmtdDB_Date_time();
        String log_tbl1 = "accb.accb_post_trns_msgs";
        long msg_id1 = Global.getLogMsgID(log_tbl1, "Posting Batch of Transactions", glBatchID);
        if (msg_id1 <= 0) {
            Global.createLogMsg(dateStr + " ....Automatic Posting Batch of Transactions is about to Start...",
                    log_tbl1, "Posting Batch of Transactions", glBatchID, dateStr);
        }
        msg_id1 = Global.getLogMsgID(log_tbl1, "Posting Batch of Transactions", glBatchID);

        Global.updateLogMsg(msg_id,
                "\r\n\r\n ....Automatic Posting Batch of Transactions is about to Start...!\r\n", log_tbl,
                dateStr, Global.rnUser_ID);

        double aesum = Global.get_COA_AESum(Global.UsrsOrg_ID);
        double crlsum = Global.get_COA_CRLSum(Global.UsrsOrg_ID);
        if (aesum != crlsum) {
            Global.updateLogMsg(msg_id1,
                    "\r\nCannot Post this Batch Since Current GL is not Balanced!Please correct the Imbalance First!\r\n",
                    log_tbl1, dateStr, Global.rnUser_ID);

            Global.updateLogMsg(msg_id,
                    "\r\nCannot Post this Batch Since Current GL is not Balanced!Please correct the Imbalance First!\r\n",
                    log_tbl, dateStr, Global.rnUser_ID);

            Program.correctImblns();

            Global.updateRptRnStopCmd(Global.runID, "1");
            Program.checkNClosePrgrm();

            return;
        }
        Global.updtActnPrcss(5);

        ResultSet dtst = Global.get_Batch_Trns(glBatchID);
        dtst.last();
        long ttltrns = dtst.getRow();
        dtst.beforeFirst();

        Global.updtActnPrcss(5);
        //Validating Entries
        if (!btchSrc.equals("Period Close Process")) {
            for (int i = 0; i < ttltrns; i++) {
                dtst.next();
                Global.updtActnPrcss(5);
                int accntid = Integer.parseInt(dtst.getString(10));
                double netAmnt = Double.parseDouble(dtst.getString(11));
                String lnDte = dtst.getString(7);
                String[] errmsg = new String[1];

                if (!Global.isTransPrmttd(accntid, lnDte, netAmnt, errmsg)) {
                    Global.updateLogMsg(msg_id1, "\r\n\r\n" + errmsg[0]
                            + "\r\n\r\nOperation Cancelled because the line with the\r\n ff details was detected as an INVALID Transaction!"
                            + "\r\nACCOUNT: " + dtst.getString(2) + "." + dtst.getString(3) + "\r\nAMOUNT: "
                            + netAmnt + "\r\nDATE: " + lnDte, log_tbl1, dateStr, Global.rnUser_ID);

                    Global.updateLogMsg(msg_id, "\r\n\r\n" + errmsg[0]
                            + "\r\n\r\nOperation Cancelled because the line with the\r\n ff details was detected as an INVALID Transaction!"
                            + "\r\nACCOUNT: " + dtst.getString(2) + "." + dtst.getString(3) + "\r\nAMOUNT: "
                            + netAmnt + "\r\nDATE: " + lnDte, log_tbl, dateStr, Global.rnUser_ID);
                    return;
                }
            }
        }
        dtst.beforeFirst();
        for (int i = 0; i < ttltrns; i++) {
            dtst.next();
            Global.updtActnPrcss(5);
            //Update the corresponding account balance and 
            //update net income balance as well if type is R or EX
            //update control account if any
            //update accnt curr bals if different from 
            int accntCurrID = Integer.parseInt(dtst.getString(18));
            int funcCurr = Integer.parseInt(dtst.getString(8));
            double accntCurrAmnt = Double.parseDouble(dtst.getString(16));

            String acctyp = Global.getAccntType(Integer.parseInt(dtst.getString(10)));
            boolean hsBnUpdt = Global.hsTrnsUptdAcntBls(Long.parseLong(dtst.getString(1)), dtst.getString(7),
                    Integer.parseInt(dtst.getString(10)));
            if (hsBnUpdt == false) {
                double dbt1 = Double.parseDouble(dtst.getString(5));
                double crdt1 = Double.parseDouble(dtst.getString(6));
                double net1 = Double.parseDouble(dtst.getString(11));

                if (funCurID != accntCurrID) {
                    Global.postAccntCurrTransaction(Integer.parseInt(dtst.getString(10)),
                            Global.getSign(dbt1) * accntCurrAmnt, Global.getSign(crdt1) * accntCurrAmnt,
                            Global.getSign(net1) * accntCurrAmnt, dtst.getString(7),
                            Long.parseLong(dtst.getString(1)), accntCurrID);
                }

                Global.postTransaction(Integer.parseInt(dtst.getString(10)), dbt1, crdt1, net1,
                        dtst.getString(7), Long.parseLong(dtst.getString(1)));
            }

            hsBnUpdt = Global.hsTrnsUptdAcntBls(Long.parseLong(dtst.getString(1)), dtst.getString(7),
                    net_accnt);

            if (hsBnUpdt == false) {
                if (acctyp.equals("R")) {
                    Global.postTransaction(net_accnt, Double.parseDouble(dtst.getString(5)),
                            Double.parseDouble(dtst.getString(6)), Double.parseDouble(dtst.getString(11)),
                            dtst.getString(7), Long.parseLong(dtst.getString(1)));
                } else if (acctyp.equals("EX")) {
                    Global.postTransaction(net_accnt, Double.parseDouble(dtst.getString(5)),
                            Double.parseDouble(dtst.getString(6)),
                            (double) (-1) * Double.parseDouble(dtst.getString(11)), dtst.getString(7),
                            Long.parseLong(dtst.getString(1)));
                }
            }

            //get control accnt id
            int cntrlAcntID = Integer.parseInt(Global.getGnrlRecNm("accb.accb_chart_of_accnts", "accnt_id",
                    "control_account_id", Integer.parseInt(dtst.getString(10))));
            if (cntrlAcntID > 0) {
                hsBnUpdt = Global.hsTrnsUptdAcntBls(Long.parseLong(dtst.getString(1)), dtst.getString(7),
                        cntrlAcntID);

                if (hsBnUpdt == false) {
                    int cntrlAcntCurrID = Integer.parseInt(Global.getGnrlRecNm("accb.accb_chart_of_accnts",
                            "accnt_id", "crncy_id", cntrlAcntID));

                    double dbt1 = Double.parseDouble(dtst.getString(5));
                    double crdt1 = Double.parseDouble(dtst.getString(6));
                    double net1 = Double.parseDouble(dtst.getString(11));

                    if (funCurID != cntrlAcntCurrID && cntrlAcntCurrID == accntCurrID) {
                        Global.postAccntCurrTransaction(cntrlAcntID, Global.getSign(dbt1) * accntCurrAmnt,
                                Global.getSign(crdt1) * accntCurrAmnt, Global.getSign(net1) * accntCurrAmnt,
                                dtst.getString(7), Long.parseLong(dtst.getString(1)), accntCurrID);
                    }
                    Global.postTransaction(cntrlAcntID, Double.parseDouble(dtst.getString(5)),
                            Double.parseDouble(dtst.getString(6)), Double.parseDouble(dtst.getString(11)),
                            dtst.getString(7), Long.parseLong(dtst.getString(1)));
                }
            }
            Global.chngeTrnsStatus(Long.parseLong(dtst.getString(1)), "1");
            Global.changeReconciledStatus(Long.parseLong(dtst.getString(21)), "1");
            Global.updateLogMsg(msg_id, "\r\nSuccessfully posted transaction ID= " + dtst.getString(1), log_tbl,
                    dateStr, Global.rnUser_ID);
            Global.updateLogMsg(msg_id1, "\r\nSuccessfully posted transaction ID= " + dtst.getString(1),
                    log_tbl1, dateStr, Global.rnUser_ID);
        }
        //Call Accnts Chart Bals Update
        Program.reloadAcntChrtBals(glBatchID, net_accnt);
        Global.updateLogMsg(msg_id, "\r\nSuccessfully Reloaded Chart of Account Balances!", log_tbl, dateStr,
                Global.rnUser_ID);

        Global.updateLogMsg(msg_id1, "\r\nSuccessfully Reloaded Chart of Account Balances!", log_tbl1, dateStr,
                Global.rnUser_ID);

        aesum = Global.get_COA_AESum(Global.UsrsOrg_ID);
        crlsum = Global.get_COA_CRLSum(Global.UsrsOrg_ID);
        if (aesum != crlsum) {
            Global.updateLogMsg(msg_id,
                    "\r\nBatch of Transactions caused an " + "IMBALANCE in the Accounting! A+E=" + aesum
                            + "\r\nC+R+L=" + crlsum + "\r\nDiff=" + (aesum - crlsum)
                            + " will be pushed to suspense Account",
                    log_tbl, dateStr, Global.rnUser_ID);
            Program.correctImblns();
            Program.correctImblns();
        } else {
            Global.updateBatchStatus(glBatchID);
            Global.updateLogMsg(msg_id, "\r\nBatch of Transactions POSTED SUCCESSFULLY!", log_tbl, dateStr,
                    Global.rnUser_ID);
        }
    } catch (SQLException ex) {
        Global.updateLogMsg(msg_id,
                "\r\nError!" + ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()), log_tbl,
                dateStr, Global.rnUser_ID);
        Global.errorLog = "\r\nError!" + ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace());
        Global.writeToLog();
    } catch (NumberFormatException ex) {
        Global.updateLogMsg(msg_id,
                "\r\nError!" + ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()), log_tbl,
                dateStr, Global.rnUser_ID);
        Global.errorLog = "\r\nError!" + ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace());
        Global.writeToLog();
    }
}

From source file:rems.RunActualRqtsfunc.java

@Override
public void run() {
    System.out.println("Running " + threadName);
    String dateStr = Global.getDB_Date_time();
    //String dateStr = Global.getDB_Date_time();
    String log_tbl = "rpt.rpt_run_msgs";
    try {/*from   w  ww  .j  ava  2 s.  c o m*/
        long prgmID = Global.getGnrlRecID("rpt.rpt_prcss_rnnrs", "rnnr_name", "prcss_rnnr_id",
                Program.runnerName);
        Global.errorLog = "Successfully Started Thread Five\r\nProgram ID:" + prgmID + ": Program Name: "
                + Program.runnerName + "\r\n";
        String[] macDet = Global.getMachDetails();
        Global.errorLog += "PID: " + Global.pid + " Running on: " + macDet[0] + " / " + macDet[1] + " / "
                + macDet[2];
        Global.writeToLog();

        String rptTitle = "";
        String jsprFileName = "";
        String[] colsToGrp = { "" };
        String[] colsToCnt = { "" };
        String[] colsToSum = { "" };
        String[] colsToAvrg = { "" };
        String[] colsToFrmt = { "" };
        String toMails = "";
        String ccMails = "";
        String bccMails = "";
        String sbjct = "";
        String msgBdy = "";
        String attchMns = "";
        long nwMsgSntID = -1;
        long toPrsnID = -1;
        long toCstmrSpplrID = -1;
        String[] errMsg = new String[1];

        if (Global.runID > 0) {
            ResultSet runDtSt = Global.get_RptRun_Det(Global.runID);
            int alertID = -1;
            long locRptID = -1;
            long msgSentID = -1;
            String paramIDs = "";
            String paramVals = "";
            String outputUsd = "";
            String orntnUsd = "";
            String imgCols = "";
            String rptLyout = "";
            String rptOutpt = "";
            String rptdlmtr = "";
            //String rptType = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "rpt_or_sys_prcs", rpt_id);
            String rptType = "";
            while (runDtSt.next()) {
                locRptID = runDtSt.getLong(6);
                alertID = runDtSt.getInt(14);
                msgSentID = runDtSt.getInt(15);
                Global.rnUser_ID = runDtSt.getLong(1);
                paramIDs = runDtSt.getString(7);
                paramVals = runDtSt.getString(8);
                outputUsd = runDtSt.getString(9);
                orntnUsd = runDtSt.getString(10);
            }

            ResultSet rptDtSt = Global.get_RptDet(locRptID);
            ResultSet alrtDtSt = Global.get_AlertDet(alertID);

            while (rptDtSt.next()) {
                imgCols = rptDtSt.getString(16);
                jsprFileName = rptDtSt.getString(20);
                rptLyout = rptDtSt.getString(15);
                rptOutpt = "";
                rptdlmtr = rptDtSt.getString(17);
                //String rptType = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "rpt_or_sys_prcs", rpt_id);
                rptType = rptDtSt.getString(6);
            }

            String alertType = "";
            if (alertID > 0) {
                while (alrtDtSt.next()) {
                    alertType = alrtDtSt.getString(6);
                }
                alrtDtSt.beforeFirst();
            }
            ResultSet prgmUntsDtSt = Global.get_AllPrgmUnts(locRptID);
            prgmUntsDtSt.last();
            long prgUntsCnt = prgmUntsDtSt.getRow();
            prgmUntsDtSt.beforeFirst();

            Global.errorLog += "\r\nRun ID: " + Global.runID + " Report ID:" + locRptID + "\r\n";
            Global.writeToLog();
            long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id",
                    "Process Run", Global.runID);

            Global.updateLogMsg(msg_id, "\r\n\r\n\r\nLog Messages ==>\r\n\r\n" + Global.errorLog, log_tbl,
                    dateStr, Global.rnUser_ID);

            Global.updateRptRn(Global.runID, "Preparing to Start...", 20);

            Global.logMsgID = msg_id;
            Global.logTbl = log_tbl;
            Global.gnrlDateStr = dateStr;

            long rpt_run_id = Global.runID;
            long rpt_id = locRptID;

            String w = "\\|";
            String seps = "\\,";
            String seps1 = "\\;";

            String[] arry1 = paramIDs.split(w);
            String[] arry2 = paramVals.split(w);
            System.out.println(paramIDs);
            Global.ovrllDataCnt = 0;
            Global.strSB = new StringBuilder("");
            //Program.updatePrgrm(prgmID);
            for (int q = 0; q < prgUntsCnt + 1; q++) {
                boolean isfirst = true;
                boolean islast = true;
                boolean shdAppnd = false;
                String rqrdParamVal = "";
                String exclFileName = "";
                if (q == prgUntsCnt) {
                    islast = true;
                } else {
                    islast = false;
                }
                if (prgUntsCnt > 0) {
                    shdAppnd = true;
                } else {
                    shdAppnd = false;
                }
                if (q == 0) {
                    isfirst = true;
                    //rpt_id = rpt_id;
                } else {
                    isfirst = false;
                    prgmUntsDtSt.next();
                    rpt_id = prgmUntsDtSt.getLong(1);
                    rptDtSt = Global.get_RptDet(rpt_id);
                    while (rptDtSt.next()) {
                        outputUsd = rptDtSt.getString(13);
                        orntnUsd = rptDtSt.getString(14);
                        jsprFileName = rptDtSt.getString(20);
                        //rptdlmtr = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "csv_delimiter", rpt_id);
                        rptLyout = rptDtSt.getString(15);
                        rptType = rptDtSt.getString(6);
                        colsToGrp = rptDtSt.getString(8).split(seps);
                        colsToCnt = rptDtSt.getString(9).split(seps);
                        colsToSum = rptDtSt.getString(10).split(seps);
                        colsToAvrg = rptDtSt.getString(11).split(seps);
                        colsToFrmt = rptDtSt.getString(12).split(seps);
                    }
                    rptDtSt.beforeFirst();
                }
                /*if (Global.callngAppType.equals("DESKTOP")) {
                if (!jsprFileName.equals("")) {
                    Global.dwnldImgsFTP(15, Global.getRptDrctry() + "/jrxmls", jsprFileName);
                }
                }*/
                String rpt_SQL = "";
                if (alertID > 0 && msgSentID <= 0) {
                    rpt_SQL = Global.get_Alert_SQL(alertID);
                } else {
                    rpt_SQL = Global.get_Rpt_SQL(rpt_id);
                }
                for (int i = 0; i < arry1.length; i++) {
                    long pID = Long.parseLong(arry1[i]);
                    int h1 = Global.findArryIdx(Global.sysParaIDs, arry1[i]);
                    if (h1 >= 0) {
                        if (arry1[i].equals("-130") && i < arry2.length) {
                            rptTitle = arry2[i];
                        } else if (arry1[i].equals("-140") && i < arry2.length) {
                            if (q == 0) {
                                colsToGrp = arry2[i].split(seps);
                            }
                        } else if (arry1[i].equals("-150") && i < arry2.length) {
                            if (q == 0) {
                                colsToCnt = arry2[i].split(seps);
                            }
                        } else if (arry1[i].equals("-160") && i < arry2.length) {
                            if (q == 0) {
                                colsToSum = arry2[i].split(seps);
                            }
                        } else if (arry1[i].equals("-170") && i < arry2.length) {
                            if (q == 0) {
                                colsToAvrg = arry2[i].split(seps);
                            }
                        } else if (arry1[i].equals("-180") && i < arry2.length) {
                            if (q == 0) {
                                colsToFrmt = arry2[i].split(seps);
                            }
                        } else if (arry1[i].equals("-190") && i < arry2.length) {
                            //colsToGrp = arry2[i].Split(seps);
                        } else if (arry1[i].equals("-200") && i < arry2.length) {
                            //colsToGrp = arry2[i].Split(seps);
                        }
                    } else if (pID > 0 && i < arry2.length - 1) {
                        String paramSqlRep = Global.getGnrlRecNm("rpt.rpt_report_parameters", "parameter_id",
                                "paramtr_rprstn_nm_in_query", pID);
                        rpt_SQL = rpt_SQL.replace(paramSqlRep, arry2[i]);
                        if (paramSqlRep.equals("{:alert_type}") && rptType.contains("Alert")) {
                            //alertType = arry2[i];
                        }
                        if (paramSqlRep.equals("{:msg_body}") && rptType.equals("Alert(SQL Mail List)")) {
                            rqrdParamVal = arry2[i];
                        } else if (paramSqlRep.equals("{:to_mail_list}")
                                && rptType.equals("Alert(SQL Message)")) {
                            rqrdParamVal = arry2[i];
                        } else if (paramSqlRep.equals("{:intrfc_tbl_name}")
                                && rptType.equals("Journal Import")) {
                            rqrdParamVal = arry2[i];
                        } else if (paramSqlRep.equals("{:orgID}")) {
                            if (Global.tryParseInt(arry2[i])) {
                                if (Integer.parseInt(arry2[i]) > 0) {
                                    Global.UsrsOrg_ID = Integer.parseInt(arry2[i]);
                                }
                            }
                        } else if (paramSqlRep.equals("{:alert_type}")) {
                            //alertType = arry2[i];
                        } else if (paramSqlRep.equals("{:excl_file_name}")) {
                            exclFileName = arry2[i];
                        } else if (paramSqlRep.equals("{:documentTitle}")) {
                            rptTitle = arry2[i];
                        }
                    }
                }

                rpt_SQL = rpt_SQL.replace("{:usrID}", String.valueOf(Global.rnUser_ID));
                rpt_SQL = rpt_SQL.replace("{:msgID}", String.valueOf(msg_id));
                rpt_SQL = rpt_SQL.replace("{:orgID}", String.valueOf(Global.UsrsOrg_ID));

                if (rptType.equals("Command Line Script")) {
                    rpt_SQL = rpt_SQL.replace("{:host_name}", Global.Hostnme);
                    rpt_SQL = rpt_SQL.replace("{:portnum}", Global.Portnum);
                }
                //NB. Be updating all report run statuses and percentages in the table
                Global.updateLogMsg(msg_id,
                        "\r\n\r\n\r\nReport/Process SQL being executed is ==>\r\n\r\n" + rpt_SQL, log_tbl,
                        dateStr, Global.rnUser_ID);
                //1. Execute SQL to get a dataset
                Global.updateRptRn(rpt_run_id, "Running SQL...", 40);
                //Program.updatePrgrm(prgmID);
                //worker.ReportProgress(40);
                ResultSet dtst = null;
                if (rptType.equals("Database Function")) {
                    Global.executeGnrlSQL(rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "));
                } else if (rptType.equals("Command Line Script")) {
                    rpt_SQL = rpt_SQL.replace("{:db_password}", Global.Pswd);
                    String batchFilnm = Global.appStatPath + "/" + "REM_DBBackup" + String.valueOf(rpt_run_id)
                            + ".bat";
                    PrintWriter fileWriter;
                    fileWriter = new PrintWriter(batchFilnm, "UTF-8");
                    StringBuilder strSB = new StringBuilder(System.getProperty("line.separator"))
                            .append(System.getProperty("line.separator"));
                    strSB.append(rpt_SQL);
                    fileWriter.println(strSB);
                    fileWriter.close();

                    Runtime runTime = Runtime.getRuntime();
                    Process process = runTime.exec(batchFilnm);
                    process.destroy();
                    Global.updateLogMsg(msg_id, "\r\n\r\nCommand Line Script Successfully Run!\r\n\r\n",
                            log_tbl, dateStr, Global.rnUser_ID);
                    boolean success = (new java.io.File(batchFilnm)).delete();
                } else if (rptType.equals("Import/Overwrite Data from Excel") && !exclFileName.equals("")) {
                    //Check if  {:alert_type} EMAIL/SMS parameter was set
                    //NB sql first column is address and 2nd col is message body
                    //Global.imprtTrnsTmp(exclFileName, rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "));
                    rpt_SQL = rpt_SQL.replace("{:orgnValColA}", "");
                } else {
                    dtst = Global.selectDataNoParams(
                            rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "));
                }
                //Report Title is Message Title if Alert
                String uptFileUrl = "";
                if (alertID > 0 && msgSentID <= 0) {
                    alrtDtSt.next();
                    ResultSet dtstPrm = Global.get_RptParams(rpt_id);
                    ResultSetMetaData dtstmd = dtst.getMetaData();
                    dtst.last();
                    int ttlRws = dtst.getRow();
                    dtst.beforeFirst();
                    int ttlCols = dtstmd.getColumnCount();
                    for (int z = 0; z < ttlRws; z++) {
                        dtst.next();
                        toPrsnID = -1;
                        toCstmrSpplrID = -1;
                        toMails = alrtDtSt.getString(3);
                        ccMails = alrtDtSt.getString(4);
                        bccMails = alrtDtSt.getString(10);
                        sbjct = alrtDtSt.getString(9);
                        msgBdy = alrtDtSt.getString(5);
                        attchMns = alrtDtSt.getString(18);

                        for (int y = 0; y < ttlCols; y++) {
                            toMails = toMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));
                            ccMails = ccMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));
                            bccMails = bccMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));
                            sbjct = sbjct.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));
                            msgBdy = msgBdy.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));
                            attchMns = attchMns.replace("{:" + dtstmd.getColumnName(y + 1) + "}",
                                    dtst.getString(y + 1));

                            if (dtstmd.getColumnName(y + 1).equals("toPrsnID")) {
                                toPrsnID = Long.parseLong(dtst.getString(y + 1));
                            }
                            if (dtstmd.getColumnName(y + 1).equals("toCstmrSpplrID")) {
                                toCstmrSpplrID = Long.parseLong(dtst.getString(y + 1));
                            }
                        }

                        Thread.sleep(1000);
                        nwMsgSntID = Global.getNewMsgSentID();
                        Global.createAlertMsgSent(nwMsgSntID, toMails, ccMails, msgBdy, dateStr, sbjct, rpt_id,
                                bccMails, toPrsnID, toCstmrSpplrID, alertID, attchMns, alertType);
                        if (alrtDtSt.getString(13).equals("1")) {
                            String prmIDs = "";
                            String prmVals = "";
                            String prmValsFnd = "";
                            dtstPrm.last();
                            int ttldtstPrm = dtstPrm.getRow();
                            dtstPrm.beforeFirst();
                            for (int x = 0; x < ttldtstPrm; x++) {
                                dtstPrm.next();
                                prmIDs += dtstPrm.getString(1) + "|";
                                prmValsFnd = dtstPrm.getString(4);
                                for (int r = 0; r < ttlCols; r++) {
                                    if (dtstPrm.getString(3).equals("{:" + dtstmd.getColumnName(r + 1) + "}")) {
                                        prmValsFnd = dtst.getString(r + 1);
                                        break;
                                    }
                                }
                                prmVals += prmValsFnd + "|";
                            }
                            String colsToGrp1 = "";
                            String colsToCnt1 = "";
                            String colsToSum1 = "";
                            String colsToAvrg1 = "";
                            String colsToFrmt1 = "";
                            String rpTitle = "";
                            while (rptDtSt.next()) {
                                colsToGrp1 = rptDtSt.getString(8);
                                colsToCnt1 = rptDtSt.getString(9);
                                colsToSum1 = rptDtSt.getString(10);
                                colsToAvrg1 = rptDtSt.getString(11);
                                colsToFrmt1 = rptDtSt.getString(12);
                                rpTitle = rptDtSt.getString(1);
                            }
                            //Report Title
                            prmVals += rpTitle + "|";
                            prmIDs += Global.sysParaIDs[0] + "|";
                            //Cols To Group
                            prmVals += colsToGrp1 + "|";
                            prmIDs += Global.sysParaIDs[1] + "|";
                            //Cols To Count
                            prmVals += colsToCnt1 + "|";
                            prmIDs += Global.sysParaIDs[2] + "|";
                            //Cols To Sum
                            prmVals += colsToSum1 + "|";
                            prmIDs += Global.sysParaIDs[3] + "|";
                            //colsToAvrg
                            prmVals += colsToAvrg1 + "|";
                            prmIDs += Global.sysParaIDs[4] + "|";
                            //colsToFrmt
                            prmVals += colsToFrmt1 + "|";
                            prmIDs += Global.sysParaIDs[5] + "|";

                            //outputUsd
                            prmVals += outputUsd + "|";
                            prmIDs += Global.sysParaIDs[6] + "|";

                            //orntnUsd
                            prmVals += orntnUsd + "|";
                            prmIDs += Global.sysParaIDs[7] + "|";

                            Program.gnrtAlertMailerfunc(rpt_id, Global.rnUser_ID, alertID, nwMsgSntID, prmIDs,
                                    prmVals, outputUsd, orntnUsd);
                        } else if (alertType.equals("Email")) {
                            errMsg = new String[1];
                            if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1),
                                    StringUtils.strip(ccMails.replace(",", ";"), seps1),
                                    StringUtils.strip(bccMails.replace(",", ";"), seps1),
                                    StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy,
                                    errMsg) == false) {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                            } else {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", "");
                            }
                        } else if (alertType.equals("SMS")) {
                            errMsg = new String[1];
                            if (Global.sendSMS(msgBdy,
                                    StringUtils.strip(
                                            (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","), seps),
                                    errMsg) == false) {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                            } else {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", "");
                            }
                        } else {

                        }
                        if ((z % 100) == 0) {
                            Thread.sleep(60000);
                        }
                    }
                } else if (rptType.equals("System Process")) {

                } else if (rptType.equals("Alert(SQL Mail List)")) {
                    //check if {:msg_body} and {:alert_type} parameter was set
                    //NB sql first column must be valid email address
                } else if (rptType.equals("Alert(SQL Mail List & Message)")) {
                    //Check if  {:alert_type} EMAIL/SMS parameter was set
                    //NB sql first column is address and 2nd col is message body
                } else if (rptType.equals("Posting of GL Trns. Batches")) {
                    //NB sql col0=batch_id, col1=batch_name, col2=batch_source, col3=batch_status, col4=batch_status_meaning
                    //i.e SQL Must Contain accb.accb_trnsctn_batches and all the colnames above
                    //
                    ResultSet wrngDtst = Global.get_WrongBalncs(Global.UsrsOrg_ID);
                    wrngDtst.last();
                    int rwCnt = wrngDtst.getRow();
                    wrngDtst.beforeFirst();
                    if (rwCnt > 0) {
                        wrngDtst.next();
                        Global.updateLogMsg(msg_id,
                                "\r\n\r\nCannot Post this Batch Since Some Accounts have wrong Balances!"
                                        + "\r\nPlease correct the Imbalance First!!\r\nUser Org ID="
                                        + Global.UsrsOrg_ID + "\r\nNumber of Records Involved=" + rwCnt
                                        + "\r\n\r\n",
                                log_tbl, dateStr, Global.rnUser_ID);
                        Program.correctImblns();
                        Global.updateRptRnStopCmd(Global.runID, "1");
                        Program.checkNClosePrgrm();
                        return;
                    } else {
                        //Check if no other accounting process is running
                        boolean isAnyRnng = true;
                        int witcntr = 0;
                        do {
                            witcntr++;
                            isAnyRnng = Global.isThereANActvActnPrcss("1,2,3,4,5,6", "10 second");
                            if (witcntr > 8) {
                                Global.updateRptRnStopCmd(Global.runID, "1");
                            }
                            Program.checkNClosePrgrm();
                            Thread.sleep(5000);
                        } while (isAnyRnng == true);

                        dtst.beforeFirst();
                        dtst.last();
                        int rwsTtl = dtst.getRow();
                        dtst.beforeFirst();
                        for (int rh = 0; rh < rwsTtl; rh++) {
                            dtst.next();
                            Global.updtActnPrcss(5);
                            Program.validateBatchNPost(Long.parseLong(dtst.getString(1)), dtst.getString(4),
                                    dtst.getString(3), msg_id, log_tbl, dateStr);
                            Thread.sleep(200);
                        }
                    }
                } else if (rptType.equals("Journal Import")) {
                    //check if {:intrfc_tbl_name} parameter was set
                    /*NB sql col0=accnt_id, col1=trnsctn_date(DD-Mon-YYYY HH24:MI:SS), 
                     * col2=dbt_amount, col3=crdt_amount, col4=net_amount, col5=func_cur_id*/
                    //
                    String[] errmsg = new String[1];
                    int prcID = 8;//Internal Payments Import Process
                    if (rqrdParamVal.equals("scm.scm_gl_interface")) {
                        prcID = 7;
                    }
                    boolean isAnyRnng = true;
                    int witcntr = 0;
                    do {
                        witcntr++;
                        isAnyRnng = Global.isThereANActvActnPrcss(String.valueOf(prcID), "10 second");
                        if (witcntr > 8) {
                            Global.updateRptRnStopCmd(Global.runID, "1");
                            Program.killThreads();
                        }
                        Program.updatePrgrm(prgmID);
                        Thread.sleep(5000);
                    } while (isAnyRnng == true);

                    Global.updtActnPrcss(prcID);
                    if (Program.sendJournalsToGL(dtst, rqrdParamVal, prcID, errmsg)) {
                        Global.updateLogMsg(msg_id, "\r\n\r\nJournals Successfully Sent to GL!\r\n" + errmsg,
                                log_tbl, dateStr, Global.rnUser_ID);
                    } else {
                        Global.updateLogMsg(msg_id, "\r\n\r\nFailed to send Journals to GL!\r\n" + errmsg,
                                log_tbl, dateStr, Global.rnUser_ID);
                    }
                } else if (rpt_id == Global.getRptID("Send Outstanding Bulk Messages")) {
                    String lastTimeChckd = Global.getDB_Date_time();
                    int lstChckCnt = 0;
                    int row_cntr = 0;
                    errMsg = new String[1];
                    boolean tmeUp = false;
                    do {
                        dateStr = lastTimeChckd;
                        if (lstChckCnt > 0) {
                            dtst = Global.selectDataNoParams(
                                    rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "));
                        }
                        dtst.last();
                        row_cntr = dtst.getRow();
                        dtst.beforeFirst();
                        for (int v = 0; v < row_cntr; v++) {
                            dtst.next();
                            String msgTyp = dtst.getString(14);
                            toMails = dtst.getString(3);
                            ccMails = dtst.getString(4);
                            bccMails = dtst.getString(8);
                            attchMns = dtst.getString(13);
                            sbjct = dtst.getString(7);
                            msgBdy = dtst.getString(5);
                            nwMsgSntID = Long.parseLong(dtst.getString(1));
                            errMsg = new String[1];
                            if (msgTyp.equals("Email")) {
                                if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1),
                                        StringUtils.strip(ccMails.replace(",", ";"), seps1),
                                        StringUtils.strip(bccMails.replace(",", ";"), seps1),
                                        StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy,
                                        errMsg) == false) {
                                    Global.updateBulkMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                                    Global.updateLogMsg(msg_id,
                                            "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails)
                                                    .replace(";", ",") + " Failed!\r\n"
                                                    + Arrays.toString(errMsg),
                                            log_tbl, dateStr, Global.rnUser_ID);
                                } else {
                                    Global.updateBulkMsgSent(nwMsgSntID, dateStr, "1", "");
                                    Global.updateLogMsg(msg_id,
                                            "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails)
                                                    .replace(";", ",") + " Successfully Sent!\r\n",
                                            log_tbl, dateStr, Global.rnUser_ID);
                                }
                            } else if (msgTyp.equals("SMS")) {
                                if (Global.sendSMS(msgBdy,
                                        StringUtils.strip(
                                                (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","),
                                                seps),
                                        errMsg) == false) {
                                    Global.updateBulkMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                                    Global.updateLogMsg(msg_id,
                                            "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails)
                                                    .replace(";", ",") + " Failed!\r\n"
                                                    + Arrays.toString(errMsg),
                                            log_tbl, dateStr, Global.rnUser_ID);
                                } else {
                                    Global.updateBulkMsgSent(nwMsgSntID, dateStr, "1", "");
                                    Global.updateLogMsg(msg_id,
                                            "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails)
                                                    .replace(";", ",") + " Successfully Sent!\r\n",
                                            log_tbl, dateStr, Global.rnUser_ID);
                                }
                            } else {

                            }

                            if (v == (row_cntr - 1)) {
                                lastTimeChckd = Global.getDB_Date_time();
                            }
                            Thread.sleep(500);

                            Global.errorLog = "\r\nMessages to " + (toMails + ";" + ccMails + ";" + bccMails)
                                    + " worked on";
                            Global.writeToLog();
                        }
                        dtst.close();
                        lstChckCnt++;
                        Thread.sleep(5000);
                        tmeUp = Global.doesDteTmExcdIntvl("30 second", lastTimeChckd);
                    } while (tmeUp == false);
                    Global.updateLogMsg(msg_id, "\r\n\r\nFinished Sending all Messages!\r\n", log_tbl, dateStr,
                            Global.rnUser_ID);
                }
                if (rpt_id == Global.getRptID("Send Outstanding Bulk Messages")) {
                    dtst = Global.selectDataNoParams(
                            rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "));
                }
                int totl = 0;
                ResultSetMetaData dtstmd = null;
                if (dtst != null) {
                    dtst.beforeFirst();
                    dtst.last();
                    totl = dtst.getRow();
                    dtst.beforeFirst();
                    dtstmd = dtst.getMetaData();
                }
                if (totl > 0) {
                    Global.updateLogMsg(msg_id,
                            "\r\n\r\nSQL Statement successfully run! Total Records = " + totl, log_tbl, dateStr,
                            Global.rnUser_ID);
                    //2. Check and Format Output in the dataset if Required
                    //Based on the 4 Output types decide what to do
                    //None|MICROSOFT EXCEL|HTML|STANDARD
                    Global.updateRptRn(rpt_run_id, "Formatting Output...", 60);
                    //Program.updatePrgrm(prgmID);
                    //worker.ReportProgress(60);
                    //String outputFileName = "";
                    rpt_SQL = rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ");
                    if (!jsprFileName.equals("")) {
                        jsprFileName = Global.getRptDrctry() + "/jrxmls/" + jsprFileName;
                        String outFlNmOnly = "";
                        if (outputUsd.equals("MICROSOFT EXCEL")) {
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".xls";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".xls";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else if (outputUsd.equals("PDF")) {
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf";
                            Global.updateLogMsg(Global.logMsgID, "\r\nBefore Jasper..." + uptFileUrl,
                                    Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID);
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else if (outputUsd.equals("HTML")) {
                            uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/"
                                    + String.valueOf(rpt_run_id) + ".html";
                            outFlNmOnly = "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else if (outputUsd.equals("STANDARD")) {
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else if (outputUsd.equals("MICROSOFT WORD")) {
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".rtf";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".rtf";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) {
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".csv";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        } else {
                            outputUsd = "PDF";
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf";
                            outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf";
                            Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL);
                        }

                        System.out.println("Finished and Opening report...");
                        if (Global.callngAppType.equals("DESKTOP")) {
                            Global.upldImgsFTP(9, Global.getRptDrctry(), outFlNmOnly);
                        }
                    } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) {
                        Global.exprtDtStToCSV(dtst,
                                Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv", isfirst,
                                islast, shdAppnd, rptdlmtr);
                        uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv";
                    } else if (outputUsd.equals("COLUMN CHART")) {
                        Global.exprtToHTMLSCC(
                                dtst, Global.getRptDrctry() + "/amcharts_2100/samples/"
                                        + String.valueOf(rpt_run_id) + ".html",
                                rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd);
                        uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/"
                                + String.valueOf(rpt_run_id) + ".html";
                    } else if (outputUsd.equals("PIE CHART"))//
                    {
                        Global.exprtToHTMLPC(
                                dtst, Global.getRptDrctry() + "/amcharts_2100/samples/"
                                        + String.valueOf(rpt_run_id) + ".html",
                                rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd);
                        uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/"
                                + String.valueOf(rpt_run_id) + ".html";
                    } else if (outputUsd.equals("LINE CHART"))//
                    {
                        Global.exprtToHTMLLC(
                                dtst, Global.getRptDrctry() + "/amcharts_2100/samples/"
                                        + String.valueOf(rpt_run_id) + ".html",
                                rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd);
                        uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/"
                                + String.valueOf(rpt_run_id) + ".html";
                    } else if (outputUsd.equals("STANDARD")) {
                        if (rptLyout.equals("None") || rptLyout.equals("TABULAR")) {
                            if (totl == 1 && dtstmd.getColumnCount() == 1) {
                                rptOutpt += dtst.getString(1);
                            } else {
                                rptOutpt += Program.formatDtSt(dtst, rptTitle, colsToGrp, colsToCnt, colsToSum,
                                        colsToAvrg, colsToFrmt);
                            }
                        } else if (rptLyout.equals("DETAIL")) {
                            //Show detail STANDARD Report
                        }
                        if (islast) {
                            Program.writeAFile(
                                    Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".txt",
                                    rptOutpt);
                            if (Global.callngAppType.equals("DESKTOP")) {
                                Global.upldImgsFTP(9, Global.getRptDrctry(),
                                        String.valueOf(Global.runID) + ".txt");
                            }
                            uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".txt";
                        }
                    } else {
                        Global.updateRptRnOutptUsd(rpt_run_id, "HTML");
                        if (rptLyout.equals("None") || rptLyout.equals("TABULAR")) {
                            Global.exprtToHTMLTblr(dtst,
                                    Global.getRptDrctry() + "/amcharts_2100/samples/"
                                            + String.valueOf(rpt_run_id) + ".html",
                                    rptTitle, colsToGrp, colsToCnt, colsToSum, colsToAvrg, colsToFrmt, isfirst,
                                    islast, shdAppnd);
                        } else if (rptLyout.equals("DETAIL")) {
                            //Show detail HTML Report
                            ResultSet grpngsDtSt = Global.get_AllGrpngs(rpt_id);
                            Global.exprtToHTMLDet(dtst, grpngsDtSt,
                                    Global.getRptDrctry() + "/amcharts_2100/samples/"
                                            + String.valueOf(rpt_run_id) + ".html",
                                    rptTitle, isfirst, islast, shdAppnd, orntnUsd, imgCols);
                        }
                        uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/"
                                + String.valueOf(rpt_run_id) + ".html";
                    }

                    Global.updateRptRn(rpt_run_id, "Storing Output...", 80);
                    //worker.ReportProgress(80);
                    Global.updateLogMsg(msg_id, "\r\n\r\nSaving Report Output...", log_tbl, dateStr,
                            Global.rnUser_ID);
                    Global.updateRptRnOutpt(rpt_run_id, rptOutpt);
                    Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Saved Report Output...", log_tbl, dateStr,
                            Global.rnUser_ID);
                    if (msgSentID > 0) {
                        Global.updateRptRn(rpt_run_id, "Sending Output...", 81);
                        Global.updateLogMsg(msg_id, "\r\n\r\nSending Report Via Mail/SMS...", log_tbl, dateStr,
                                Global.rnUser_ID);
                        ResultSet msgDtSt = Global.get_MsgSentDet(msgSentID);
                        msgDtSt.next();

                        toMails = msgDtSt.getString(1);
                        ccMails = msgDtSt.getString(2);
                        bccMails = msgDtSt.getString(7);
                        sbjct = msgDtSt.getString(5);
                        msgBdy = msgDtSt.getString(3);
                        attchMns = msgDtSt.getString(15) + ";" + uptFileUrl;
                        toPrsnID = Long.parseLong(msgDtSt.getString(8));
                        toCstmrSpplrID = Long.parseLong(msgDtSt.getString(9));
                        alertType = msgDtSt.getString(16);
                        errMsg = new String[1];
                        if (alertType.equals("Email")) {
                            if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1),
                                    StringUtils.strip(ccMails.replace(",", ";"), seps1),
                                    StringUtils.strip(bccMails.replace(",", ";"), seps1),
                                    StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy,
                                    errMsg) == false) {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                            } else {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", "");
                            }
                        } else if (alertType.equals("SMS")) {
                            if (Global.sendSMS(msgBdy,
                                    StringUtils.strip(
                                            (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","), seps),
                                    errMsg) == false) {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg));
                            } else {
                                Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", "");
                            }
                        } else {
                        }
                        Thread.sleep(1500);
                    }
                    Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Completed Process/Report Run...", log_tbl,
                            dateStr, Global.rnUser_ID);
                    Global.updateRptRn(rpt_run_id, "Completed!", 100);

                    if (rptType.equals("Alert(SQL Message)")) {
                        //check if {:to_mail_list} and {:alert_type}  parameter was set
                        //NB entire sql output is message body 
                        //Report Output file must be added as attachment
                    }
                } else {
                    Global.updateLogMsg(msg_id, "\r\n\r\nSQL Statement yielded no Results!", log_tbl, dateStr,
                            Global.rnUser_ID);
                    Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Completed Process/Report Run...", log_tbl,
                            dateStr, Global.rnUser_ID);
                    Global.updateRptRn(rpt_run_id, "Completed!", 100);
                }
            }
            Program.killThreads();
        }
        Program.killThreads();
    } catch (SQLException ex) {
        Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n";
        Global.writeToLog();
        Global.updateRptRn(Global.runID, "Error!", 100);

        long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id",
                "Process Run", Global.runID);
        Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog,
                log_tbl, dateStr, Global.rnUser_ID);
        Program.killThreads();
    } catch (NumberFormatException ex) {
        Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n";
        Global.writeToLog();
        Global.updateRptRn(Global.runID, "Error!", 100);

        long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id",
                "Process Run", Global.runID);
        Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog,
                log_tbl, dateStr, Global.rnUser_ID);
        Program.killThreads();
    } catch (IOException ex) {
        Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n";
        Global.writeToLog();
        Global.updateRptRn(Global.runID, "Error!", 100);

        long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id",
                "Process Run", Global.runID);
        Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog,
                log_tbl, dateStr, Global.rnUser_ID);
        Program.killThreads();
    } catch (InterruptedException ex) {
        Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n";
        Global.writeToLog();
        Global.updateRptRn(Global.runID, "Error!", 100);

        long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id",
                "Process Run", Global.runID);
        Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog,
                log_tbl, dateStr, Global.rnUser_ID);
        Program.killThreads();
    } finally {
    }
}