Example usage for java.sql ResultSet beforeFirst

List of usage examples for java.sql ResultSet beforeFirst

Introduction

In this page you can find the example usage for java.sql ResultSet beforeFirst.

Prototype

void beforeFirst() throws SQLException;

Source Link

Document

Moves the cursor to the front of this ResultSet object, just before the first row.

Usage

From source file:rems.Program.java

private static void reloadAcntChrtBals(int netaccntid) {
    try {//from ww  w.  j  a  va 2 s. c  o  m
        SimpleDateFormat frmtr = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
        SimpleDateFormat frmtr1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = frmtr.format(frmtr1.parse(Global.getDB_Date_time()).getTime());

        ResultSet dtst = Global.get_All_Chrt_Det(Global.UsrsOrg_ID);
        dtst.last();
        int ttlRws = dtst.getRow();
        dtst.beforeFirst();
        for (int a = 0; a < ttlRws; a++) {
            dtst.next();
            String[] rslt = Global.getAccntLstDailyBalsInfo(Integer.parseInt(dtst.getString(1)), dateStr);
            double lstNetBals = Double.parseDouble(rslt[2]);
            double lstDbtBals = Double.parseDouble(rslt[0]);
            double lstCrdtBals = Double.parseDouble(rslt[1]);

            Global.updtAcntChrtBals(Integer.parseInt(dtst.getString(1)), lstDbtBals, lstCrdtBals, lstNetBals,
                    rslt[3]);

            //get control accnt id
            int cntrlAcntID = Integer.parseInt(Global.getGnrlRecNm("accb.accb_chart_of_accnts", "accnt_id",
                    "control_account_id", Integer.parseInt(dtst.getString(1))));
            if (cntrlAcntID > 0) {
                rslt = Global.getAccntLstDailyBalsInfo(cntrlAcntID, dateStr);
                lstNetBals = Double.parseDouble(rslt[2]);
                lstDbtBals = Double.parseDouble(rslt[0]);
                lstCrdtBals = Double.parseDouble(rslt[1]);

                //Global.showMsg("Testing!" + rslt[2] + "\r\n" + rslt[3] + "\r\n" + dateStr, 0);
                Global.updtAcntChrtBals(cntrlAcntID, lstDbtBals, lstCrdtBals, lstNetBals, rslt[3]);
            }
        }
        if (netaccntid > 0) {
            String[] rslt = Global.getAccntLstDailyBalsInfo(netaccntid, dateStr);
            double lstNetBals = Double.parseDouble(rslt[2]);
            double lstDbtBals = Double.parseDouble(rslt[0]);
            double lstCrdtBals = Double.parseDouble(rslt[1]);

            //Global.showMsg("Testing!" + rslt[2] + "\r\n" + rslt[3] + "\r\n" + dateStr, 0);
            Global.updtAcntChrtBals(netaccntid, lstDbtBals, lstCrdtBals, lstNetBals, rslt[3]);
        }
    } catch (ParseException ex) {

    } catch (SQLException ex) {
    } catch (NumberFormatException ex) {
    }
}

From source file:main.export.sql.DocBuilder.java

@SuppressWarnings("unchecked")
public Map<String, Object> getFields(Map<String, Object> firstRow, ResultSet rs, Entity entity,
        Map<String, Object> entityMap, Map<String, Object> rootEntityMap) throws SQLException {

    entityMap = new HashMap<String, Object>();

    if (entity.allAttributes.get(MULTI_VALUED) != null
            && entity.allAttributes.get(MULTI_VALUED).equalsIgnoreCase("true")) {
        List<Object> fieldArray = new ArrayList<Object>();
        rs.beforeFirst();
        while (rs.next()) {
            if (entity.fields.size() > 1) {
                Map<String, Object> entityFieldsMap = new HashMap<String, Object>();
                for (Iterator<Field> iterator = entity.fields.iterator(); iterator.hasNext();) {
                    Field field = (Field) iterator.next();
                    FieldType fieldType = FieldType.valueOf(field.allAttributes.get("type").toUpperCase());
                    entityFieldsMap.put(field.name,
                            convertFieldType(fieldType, rs.getObject(field.column)).get(0));
                }//ww w.j  ava  2s  . co m
                fieldArray.add(entityFieldsMap);
            } else if (entity.fields.size() == 1) {
                fieldArray.add(rs.getObject(entity.fields.get(0).column));
            }
        }
        rootEntityMap.put(entity.name, fieldArray);
    } else if (firstRow != null) {
        for (Iterator<Field> iterator = entity.fields.iterator(); iterator.hasNext();) {
            Field field = (Field) iterator.next();
            FieldType fieldType = FieldType.valueOf(field.allAttributes.get("type").toUpperCase());

            if (firstRow.get(field.column) != null) {
                if (entity.pk != null && entity.pk.equals(field.name)) {
                    if (importer.getDataStoreType().equals(DataStoreType.MONGO)) {
                        entityMap.put("_id", convertFieldType(fieldType, firstRow.get(field.column)).get(0));
                    } else if (importer.getDataStoreType().equals(DataStoreType.COUCH)) {
                        // couch db says document id must be string
                        entityMap.put("_id",
                                convertFieldType(FieldType.STRING, firstRow.get(field.column)).get(0));
                    }
                } else {
                    entityMap.put(field.getName(),
                            convertFieldType(fieldType, firstRow.get(field.column)).get(0));
                }

                params.put(entity.name + "." + field.name, firstRow.get(field.column).toString());
            }

        }
    }

    if (entity.entities != null) {
        Entity subEntity = null;
        String query = "", aparam = "";
        for (Iterator<Entity> iterator = entity.entities.iterator(); iterator.hasNext();) {
            subEntity = (Entity) iterator.next();
            subLevel = subConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            query = subEntity.allAttributes.get("query");

            m = p.matcher(query);
            aparam = "";
            try {
                log.info("Parameter Map is: " + params);
                while (m.find()) {
                    aparam = query.substring(m.start() + 2, m.end() - 1);
                    query = query.replaceAll("(\\$\\{" + aparam + "\\})",
                            Matcher.quoteReplacement(StringEscapeUtils.escapeSql(params.get(aparam))));
                    m = p.matcher(query);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            resultSet = subLevel.executeQuery(query);
            if (resultSet.next()) {
                subEntityData = getFields(processor.toMap(resultSet), resultSet, subEntity, null, entityMap);
                if (subEntityData.size() > 0)
                    entityMap.put(subEntity.name, subEntityData);
            }
            resultSet.close();
            subLevel.close();
        }
    }
    return entityMap;
}

From source file:rems.Program.java

private static boolean postIntoSuspnsAccnt(BigDecimal aeVal, BigDecimal crlVal, int orgID, boolean isspcl,
        String[] errmsg) {//  w ww . ja  v a2  s.  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:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java

private int getNumRows(final ResultSet rs) throws SQLException {
    if (!rs.last()) {
        return 0;
    }/*from  w  w  w . j a  va2s.c o  m*/
    int result = rs.getRow();
    rs.beforeFirst();
    return result;
}

From source file:rems.Program.java

private static void correctIntrfcImbals(String intrfcTblNm) {
    try {/*from  www.  j av  a 2 s  .c  o  m*/
        int suspns_accnt = Global.get_Suspns_Accnt(Global.UsrsOrg_ID);
        ResultSet dteDtSt = Global.get_Intrfc_dateSums(intrfcTblNm, Global.UsrsOrg_ID);
        dteDtSt.last();
        int ttlRws = dteDtSt.getRow();
        dteDtSt.beforeFirst();
        if (ttlRws > 0 && suspns_accnt > 0) {
            String msg1 = "";
            for (int i = 0; i < ttlRws; i++) {
                dteDtSt.next();
                double dlyDbtAmnt = Double.parseDouble(dteDtSt.getString(2));
                double dlyCrdtAmnt = Double.parseDouble(dteDtSt.getString(3));
                int orgID = Global.UsrsOrg_ID;
                if (dlyDbtAmnt != dlyCrdtAmnt) {
                    //long suspns_batch_id = glBatchID;
                    int funcCurrID = Global.getOrgFuncCurID(orgID);
                    BigDecimal dffrnc = BigDecimal.valueOf(dlyDbtAmnt - dlyCrdtAmnt);
                    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();

                    SimpleDateFormat frmtr = new SimpleDateFormat("dd-MMM-yyyy");
                    SimpleDateFormat frmtr1 = new SimpleDateFormat("yyyy-MM-dd");
                    String dateStr1 = frmtr.format(frmtr1.parse(dteDtSt.getString(1)).getTime()) + " 00:00:00";

                    String dateStr = Global.getFrmtdDB_Date_time();

                    if (Global.getIntrfcTrnsID(intrfcTblNm, suspns_accnt, netAmnt,
                            dteDtSt.getString(1) + " 00:00:00") > 0) {
                        continue;
                    }

                    if (Global.dbtOrCrdtAccnt(suspns_accnt, incrsDcrs).equals("Debit")) {
                        if (intrfcTblNm.equals("scm.scm_gl_interface")) {
                            Global.createScmGLIntFcLn(suspns_accnt,
                                    "Correction of Imbalance in GL Interface Table as at " + dateStr1,
                                    imbalAmnt.doubleValue(), dateStr1, funcCurrID, 0, netAmnt,
                                    "Imbalance Correction", -1, -1, dateStr, "USR");
                        } else {
                            Global.createPayGLIntFcLn(suspns_accnt,
                                    "Correction of Imbalance in GL Interface Table as at " + dateStr1,
                                    imbalAmnt.doubleValue(), dateStr1, funcCurrID, 0, netAmnt, dateStr, "USR");
                        }
                    } else if (intrfcTblNm.equals("scm.scm_gl_interface")) {
                        Global.createScmGLIntFcLn(suspns_accnt,
                                "Correction of Imbalance in GL Interface Table as at " + dateStr1, 0, dateStr1,
                                funcCurrID, imbalAmnt.doubleValue(), netAmnt, "Imbalance Correction", -1, -1,
                                dateStr, "USR");
                    } else {
                        Global.createPayGLIntFcLn(suspns_accnt,
                                "Correction of Imbalance in GL Interface Table as at " + dateStr1,
                                imbalAmnt.doubleValue(), dateStr1, funcCurrID, 0, netAmnt, dateStr, "USR");
                    }
                }
            }
        } else {
            //Global.mnFrm.cmCde.showMsg("There's no Imbalance to correct!", 0);
            //return;
        }
    } catch (SQLException ex) {

    } catch (NumberFormatException ex) {
    } catch (ParseException ex) {
    }
}

From source file:Data.java

private JTable getTbleData(Statement stmt) throws SQLException, ClassNotFoundException {
    ResultSet rs;
    String sql = "SELECT pro_name, pro_description, COUNT(sto_uid) - (SUM(sto_inout) * 2) AS NbProduit FROM t_produit, t_stock WHERE t_produit.id_produit = t_stock.id_produit GROUP BY t_produit.id_produit";

    rs = stmt.executeQuery(sql);/*from w w  w.j  av a 2 s  .  c om*/

    rs.last();
    Object rowData[][] = new Object[rs.getRow()][3];

    rs.beforeFirst();

    while (rs.next()) {
        rowData[rs.getRow() - 1][0] = rs.getString(1);
        rowData[rs.getRow() - 1][1] = rs.getString(2);
        rowData[rs.getRow() - 1][2] = rs.getInt(3);
    }

    sql = "SELECT tmp_temperature, tmp_humidity FROM t_temphum ORDER BY tmp_date DESC LIMIT 1";

    rs = stmt.executeQuery(sql);
    rs.first();

    if (tempUnit == "C") {
        tempRealTime.setText("Temprature : " + rs.getDouble(1) + "" + tempUnit);
    } else {
        tempRealTime.setText("Temprature : " + celsiusToFahrenheit(rs.getString(1)) + "" + tempUnit);
    }
    humRealTime.setText("Humidit : " + rs.getDouble(2) + "%");

    lastTemp = rs.getDouble(1);
    lastHum = rs.getDouble(2);

    Object columnNames[] = { "Poduit", "Description", "Quantit" };
    JTable table = new JTable(rowData, columnNames);

    return table;

}

From source file:com.oracle.tutorial.jdbc.CoffeesTable.java

public void insertRow(String coffeeName, int supplierID, float price, int sales, int total)
        throws SQLException {
    Statement stmt = null;//from  ww  w. j  av a2s.  co m
    try {
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");

        uprs.moveToInsertRow();

        uprs.updateString("COF_NAME", coffeeName);
        uprs.updateInt("SUP_ID", supplierID);
        uprs.updateFloat("PRICE", price);
        uprs.updateInt("SALES", sales);
        uprs.updateInt("TOTAL", total);

        uprs.insertRow();
        uprs.beforeFirst();

    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

From source file:rems.Program.java

public static void correctImblns() {
    try {//from   ww  w . j  a  v a 2 s .c  om
        int suspns_accnt = Global.get_Suspns_Accnt(Global.UsrsOrg_ID);
        if (suspns_accnt <= -1) {
            //Global.showMsg("Please define a suspense Account First!", 0);
            return;
        }
        int ret_accnt = Global.get_Rtnd_Erngs_Accnt(Global.UsrsOrg_ID);
        int net_accnt = Global.get_Net_Income_Accnt(Global.UsrsOrg_ID);
        if (ret_accnt == -1) {
            //Global.showMsg("Until a Retained Earnings Account is defined\r\n no Transaction can be posted into the Accounting!", 0);
            return;
        }
        if (net_accnt == -1) {
            //Global.showMsg("Until a Net Income Account is defined\r\n no Transaction can be posted into the Accounting!", 0);
            return;
        }
        /*PROCEDURE FOR RELOADING ACCOUNT BALANCES
         1. Correct all Trns Det Net Balance Amount
         2. Get all wrong daily bals values
         */
        Global.updtActnPrcss(5, 90);
        ResultSet dtst = Global.get_WrongNetBalncs(Global.UsrsOrg_ID);
        dtst.last();
        int ttlRws = dtst.getRow();
        dtst.beforeFirst();
        for (int i = 0; i < ttlRws; i++) {
            dtst.next();
            double netAmnt = Double.parseDouble(dtst.getString(9));
            long trnsID = Long.parseLong(dtst.getString(1));
            String updtSQL = "UPDATE accb.accb_trnsctn_details " + "SET net_amount=" + netAmnt
                    + " WHERE transctn_id=" + trnsID;
            Global.updateDataNoParams(updtSQL);
            Global.updtActnPrcss(5, 90);
        }

        dtst = Global.get_WrongBalncs(Global.UsrsOrg_ID);
        dtst.last();
        ttlRws = dtst.getRow();
        dtst.beforeFirst();
        for (int i = 0; i < ttlRws; i++) {
            dtst.next();
            Global.updtActnPrcss(5, 30);

            String acctyp = Global.getAccntType(Integer.parseInt(dtst.getString(2)));

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

            Global.postTransaction(Integer.parseInt(dtst.getString(2)), dbt1, crdt1, net1, dtst.getString(8),
                    -993);

            if (acctyp.equals("R")) {
                Global.postTransaction(net_accnt, dbt1, crdt1, net1, dtst.getString(8), -993);
            } else if (acctyp.equals("EX")) {
                Global.postTransaction(net_accnt, dbt1, crdt1, (double) (-1) * net1, dtst.getString(8), -993);
            }

            //get control accnt id
            int cntrlAcntID = Integer.parseInt(Global.getGnrlRecNm("accb.accb_chart_of_accnts", "accnt_id",
                    "control_account_id", Integer.parseInt(dtst.getString(2))));
            if (cntrlAcntID > 0) {
                Global.postTransaction(cntrlAcntID, dbt1, crdt1, net1, dtst.getString(8), -993);
            }
            //this.reloadOneAcntChrtBals(Integer.parseInt(dtst.Tables[0].Rows[i][1].ToString()), net_accnt);
        }

        Global.updtActnPrcss(5, 50);
        Program.reloadAcntChrtBals(net_accnt);

        dtst = Global.get_WrongNetIncmBalncs(Global.UsrsOrg_ID);
        dtst.last();
        ttlRws = dtst.getRow();
        dtst.beforeFirst();

        for (int i = 0; i < ttlRws; i++) {
            dtst.next();
            Global.updtActnPrcss(5, 30);
            String acctyp = Global.getAccntType(Integer.parseInt(dtst.getString(2)));

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

            Global.postTransaction(Integer.parseInt(dtst.getString(2)), dbt1, crdt1, net1, dtst.getString(8),
                    -993);
        }

        Global.updtActnPrcss(5, 50);
        Program.reloadOneAcntChrtBals(net_accnt, net_accnt);

        String[] errmsg = new String[1];
        BigDecimal aesum = BigDecimal.valueOf(Global.get_COA_AESum(Global.UsrsOrg_ID));
        BigDecimal crlsum = BigDecimal.valueOf(Global.get_COA_CRLSum(Global.UsrsOrg_ID));
        if (aesum != crlsum) {
            Global.updtActnPrcss(5, 10);
            if (Program.postIntoSuspnsAccnt(aesum, crlsum, Global.UsrsOrg_ID, false, errmsg) == false
                    && !errmsg[0].equals("")) {
                // Global.showMsg(errmsg, 0);
            }
        }

        Program.reloadOneAcntChrtBals(suspns_accnt, net_accnt);
        Global.updtActnPrcss(5, 1);
    } catch (SQLException ex) {

    } catch (NumberFormatException ex) {
    }
}

From source file:sample.products.java

private String getResults(String query, String... params) {
    StringBuilder sb = new StringBuilder();
    //  return "s";  
    StringWriter out = new StringWriter();
    ResultSet rs;
    int rows = 0;
    JSONArray products = new JSONArray();
    try (Connection cn = connection.getConnection()) {
        PreparedStatement pstmt = cn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }/*from  w w w  .  j  a  v  a2 s  .  com*/
        rs = pstmt.executeQuery();
        if (rs.last()) {
            rows = rs.getRow();
        }
        System.out.println(rows);
        rs.beforeFirst();
        if (rows > 1) {
            while (rs.next()) {
                //sb.append(String.format("%s\t%s\t%s\t%s\n", rs.getInt("productId"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"))); 
                JsonObject json = Json.createObjectBuilder().add("Product Id", rs.getInt("productId"))
                        .add("Name", rs.getString("name")).add("Description", rs.getString("description"))
                        .add("Quantity", rs.getString("quantity")).build();
                products.add(json);

            }
        } else {
            while (rs.next()) {
                JsonObject json = Json.createObjectBuilder().add("Product Id", rs.getInt("productId"))
                        .add("Name", rs.getString("name")).add("Description", rs.getString("description"))
                        .add("Quantity", rs.getString("quantity")).build();
                return json.toString();
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex);
    }
    return products.toString();
}

From source file:rems.Program.java

public static void validateBatchNPost(long glBatchID, String batchStatus, String batchSource, long msg_id,
        String log_tbl, String dateStr) {
    try {//from   w w w . java 2  s .co  m
        SimpleDateFormat frmtr = new SimpleDateFormat("dd-MMM-yyyy");
        SimpleDateFormat frmtr1 = new SimpleDateFormat("yyyy-MM-dd");

        Global.updtActnPrcss(5);
        batchStatus = Global.getGnrlRecNm("accb.accb_trnsctn_batches", "batch_id", "batch_status", glBatchID);
        if (batchStatus.equals("1")) {
            Global.updateLogMsg(msg_id, "\r\nCannot Post an already Posted Batch of Transactions!\r\n", log_tbl,
                    dateStr, Global.rnUser_ID);

            return;
        }
        int suspns_accnt = Global.get_Suspns_Accnt(Global.UsrsOrg_ID);
        ResultSet dteDtSt = Global.get_Batch_dateSums(glBatchID);
        dteDtSt.last();
        int ttlRows = dteDtSt.getRow();
        dteDtSt.beforeFirst();
        if (ttlRows > 0 && suspns_accnt > 0) {
            String msg1 = "";
            for (int i = 0; i < ttlRows; i++) {
                dteDtSt.next();
                double dlyDbtAmnt = Double.parseDouble(dteDtSt.getString(2));
                double dlyCrdtAmnt = Double.parseDouble(dteDtSt.getString(3));
                int orgID = Global.UsrsOrg_ID;
                if (dlyDbtAmnt != dlyCrdtAmnt) {
                    long suspns_batch_id = glBatchID;
                    int funcCurrID = Global.getOrgFuncCurID(orgID);
                    BigDecimal dffrnc = BigDecimal.valueOf(dlyDbtAmnt - dlyCrdtAmnt);
                    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 dateStr1 = frmtr.format(frmtr1.parse(dteDtSt.getString(1)).getTime()) + " 00:00:00";

                    if (Global.dbtOrCrdtAccnt(suspns_accnt, incrsDcrs).equals("Debit")) {
                        Global.createTransaction(suspns_accnt,
                                "Correction of Imbalance in GL Batch " + Global.getGnrlRecNm(
                                        "accb.accb_trnsctn_batches", "batch_id", "batch_name", glBatchID)
                                        + " as at " + dateStr1,
                                imbalAmnt.doubleValue(), dateStr1, 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 in GL Batch " + Global.getGnrlRecNm(
                                        "accb.accb_trnsctn_batches", "batch_id", "batch_name", glBatchID)
                                        + " as at " + dateStr1,
                                0.00, dateStr1, funcCurrID, suspns_batch_id, imbalAmnt.doubleValue(), netAmnt,
                                imbalAmnt.doubleValue(), funcCurrID, imbalAmnt.doubleValue(), funcCurrID,
                                (double) 1, (double) 1, "C");
                    }
                }
            }
        } else {
            //Global.mnFrm.cmCde.showMsg("There's no Imbalance to correct!", 0);
            //return;
        }

        if (Global.get_Batch_CrdtSum(glBatchID) != Global.get_Batch_DbtSum(glBatchID)) {
            Global.updateLogMsg(msg_id, "\r\nCannot Post an Unbalanced Batch of Transactions!\r\n", log_tbl,
                    dateStr, Global.rnUser_ID);
            return;
        }

        Global.updtActnPrcss(5);
        ResultSet dtst = Global.get_Batch_Trns_NoStatus(glBatchID);
        dtst.last();
        long ttltrns = dtst.getRow();
        dtst.beforeFirst();
        if (ttltrns <= 0 && !batchSource.equals("Period Close Process")) {
            Global.updateLogMsg(msg_id,
                    "\r\nOnly Period Close Process Batches can be posted when the batch has no transactions!\r\n",
                    log_tbl, dateStr, Global.rnUser_ID);
            return;
        }
        int ret_accnt = Global.get_Rtnd_Erngs_Accnt(Global.UsrsOrg_ID);
        int net_accnt = Global.get_Net_Income_Accnt(Global.UsrsOrg_ID);
        if (ret_accnt == -1) {
            Global.updateLogMsg(msg_id,
                    "\r\nUntil a Retained Earnings Account is defined\r\n no Transaction can be posted into the Accounting!\r\n",
                    log_tbl, dateStr, Global.rnUser_ID);
            return;
        }
        if (net_accnt == -1) {
            Global.updateLogMsg(msg_id,
                    "\r\nUntil a Net Income Account is defined\r\n no Transaction can be posted into the Accounting!\r\n",
                    log_tbl, dateStr, Global.rnUser_ID);
            return;
        }
        Global.updtActnPrcss(5);

        ResultSet dteDtSt1 = Global.get_Batch_dateSums(glBatchID);
        dteDtSt1.last();
        int dteDtSt1Ttl = dteDtSt1.getRow();
        dteDtSt1.beforeFirst();
        if (dteDtSt1Ttl > 0) {
            String msg1 = "Your transactions will cause your Balance Sheet to become Unbalanced on some Days!"
                    + "Please make sure each day has equal debits and credits. Check the ff Days:" + "\r\n";
            for (int i = 0; i < dteDtSt1Ttl; i++) {
                dteDtSt1.next();
                msg1 = msg1 + dteDtSt1.getString(1) + "\t DR=" + dteDtSt1.getString(2) + "\t CR="
                        + dteDtSt1.getString(3) + "\r\n";
            }
            Global.updateLogMsg(msg_id, "\r\n" + msg1 + "!\r\n", log_tbl, dateStr, Global.rnUser_ID);
            return;
        }
        int funCurID = Global.getOrgFuncCurID(Global.UsrsOrg_ID);
        Global.updtActnPrcss(5);
        Program.postGLBatch(glBatchID, batchSource, msg_id, log_tbl, dateStr, net_accnt, funCurID);
    } catch (SQLException ex) {
    } catch (NumberFormatException ex) {
    } catch (ParseException ex) {
    }
}