List of usage examples for com.google.gson JsonArray add
public void add(JsonElement element)
From source file:account.DailyCashSummary.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. j a v a 2 s.c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "SELECT doc_date,branch_cd,SUM(CASE WHEN CRDR=0 THEN val ELSE 0 END) AS dr_bal,SUM(CASE WHEN CRDR=0 THEN val ELSE val*-1 END) AS bal" + ",SUM(CASE WHEN CRDR=1 THEN val*-1 ELSE 0 END) AS cr_bal FROM oldb2_2 \n" + " WHERE ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd IN (SELECT grp_cd FROM groupmst WHERE group_name='CASH')) " + " AND doc_cd <>'SL' AND doc_cd <>'CO' " + " and doc_date>='" + from_date + "' " + " and doc_date<='" + to_date + "' and branch_cd =" + branch_cd + " group by doc_date,branch_cd"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("v_date", viewDataRs.getString("doc_date")); object.addProperty("dr_bal", viewDataRs.getDouble("dr_bal")); object.addProperty("cr_bal", viewDataRs.getDouble("cr_bal")); object.addProperty("bal", viewDataRs.getDouble("bal")); object.addProperty("branch_cd", viewDataRs.getDouble("branch_cd")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.DailySalesStatement.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww . ja va 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int mode = Integer.parseInt(request.getParameter("mode")); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select v.branch_cd,v.v_date,sum(v.ins_amt) as ins,sum(net_amt) as net_amt,sum(v.head_disc) as MOP," + "sum(v.BUY_BACK_AMT) as buy_back,(SELECT SUM(disc_rate) FROM vilsdt v1 WHERE v1.REF_NO=v.REF_NO)AS adjst" + ",sum(p.CASH_AMT) as cash," + "sum(p.CARD_AMT) as card,sum(p.BANK_AMT) as bank,sum(p.BAJAJ_AMT) as bajaj" + " from VILSHD v left join PAYMENT p on v.REF_NO=p.REF_NO where is_del =0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "'"; if (mode != 2) { sql += " and v.V_TYPE=" + mode; } if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } sql += " group by v.v_date,v.branch_cd"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("v_date", viewDataRs.getString("v_date")); object.addProperty("ins", viewDataRs.getDouble("ins")); object.addProperty("net_amt", viewDataRs.getDouble("net_amt")); object.addProperty("buy_back", viewDataRs.getDouble("buy_back")); object.addProperty("cash", viewDataRs.getDouble("cash")); object.addProperty("card", viewDataRs.getString("card")); object.addProperty("bank", viewDataRs.getString("bank")); object.addProperty("bajaj", viewDataRs.getString("bajaj")); object.addProperty("adjst", viewDataRs.getString("adjst")); object.addProperty("MOP", viewDataRs.getString("MOP")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.DailySalesStatementDetail.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . ja v a2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int mode = Integer.parseInt(request.getParameter("mode")); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "SELECT v.branch_cd,v.inv_no,v.v_type,a.fname,v.v_date,(p.card_chg+p.bajaj_chg) AS ins,(NET_AMT) AS net_amt,SUM(v1.DISC_RATE) AS adjst,\n" + " (v.BUY_BACK_AMT) AS buy_back,(p.CASH_AMT) AS cash,(p.CARD_AMT) AS card,(p.BANK_AMT) AS bank,(p.BAJAJ_AMT) AS bajaj,(p.DISC_AMT) AS mop " + " ,p.card_no,tid_no FROM VILSHD v LEFT JOIN PAYMENT p ON v.REF_NO=p.REF_NO LEFT JOIN acntmst a ON v.ac_cd=a.ac_cd\n" + " LEFT JOIN vilsdt v1 ON v.REF_NO=v1.REF_NO WHERE is_del =0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "'"; if (mode != 2) { sql += " and v.V_TYPE=" + mode; } if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } sql += " GROUP BY v.REF_NO order by v.v_date,v.v_type,v.inv_no"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("inv_no", viewDataRs.getString("inv_no")); object.addProperty("v_type", viewDataRs.getString("v_type")); object.addProperty("fname", viewDataRs.getString("fname")); object.addProperty("v_date", viewDataRs.getString("v_date")); object.addProperty("ins", viewDataRs.getDouble("ins")); object.addProperty("net_amt", viewDataRs.getDouble("net_amt")); object.addProperty("buy_back", viewDataRs.getDouble("buy_back")); object.addProperty("cash", viewDataRs.getDouble("cash")); object.addProperty("card", viewDataRs.getString("card")); object.addProperty("bank", viewDataRs.getString("bank")); object.addProperty("bajaj", viewDataRs.getString("bajaj")); object.addProperty("adjst", viewDataRs.getString("adjst")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); object.addProperty("MOP", viewDataRs.getString("MOP")); object.addProperty("card_no", viewDataRs.getString("card_no")); object.addProperty("tid_no", viewDataRs.getString("tid_no")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.DCRegister.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j av a2s. co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final String ac_cd = request.getParameter("ac_cd"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final String sr_cd = request.getParameter("sr_cd"); final String type_cd = request.getParameter("type_cd"); final String brand_cd = request.getParameter("brnad_cd"); final String model_cd = request.getParameter("model_cd"); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select d.ref_no,FNAME,d.INV_NO,d.V_DATE,d1.TAG_NO,s.SR_NAME,d1.RATE,d1.remark from DCHD d left join DCDT d1 on d.REF_NO=d1.REF_NO " + " left join ACNTMST a on d.AC_CD=a.AC_CD left join SERIESMST s on d1.SR_CD=s.SR_CD " + " left join modelmst m on m.model_cd = s.model_cd where d.IS_DEL=0" + " and d.v_date>='" + from_date + "' " + " and d.v_date<='" + to_date + "' "; if (!type_cd.equalsIgnoreCase("")) { sql += " and m.type_cd='" + type_cd + "' "; } if (!sr_cd.equalsIgnoreCase("")) { sql += " and s.SR_CD='" + sr_cd + "'"; } else if (!brand_cd.equalsIgnoreCase("")) { sql += " and s.brand_cd='" + brand_cd + "'"; } else if (!model_cd.equalsIgnoreCase("")) { sql += " and s.model_cd='" + model_cd + "'"; } if (!ac_cd.equalsIgnoreCase("")) { sql += " and d.ac_cd='" + ac_cd + "'"; } pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("FNAME", viewDataRs.getString("FNAME")); object.addProperty("SR_NAME", viewDataRs.getString("SR_NAME")); object.addProperty("V_DATE", viewDataRs.getString("V_DATE")); object.addProperty("RATE", viewDataRs.getDouble("RATE")); object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO")); object.addProperty("REF_NO", viewDataRs.getString("REF_NO")); object.addProperty("REMARK", viewDataRs.getString("REMARK")); array.add(object); } jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } } response.getWriter().print(jResultObj); }
From source file:account.EOD.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w .j a v a2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int mode = Integer.parseInt(request.getParameter("mode")); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select sum(v.ins_amt) as ins,sum(net_amt) as net_amt,sum(v.head_disc) as MOP," + "sum(v.BUY_BACK_AMT) as buy_back,(SELECT SUM(disc_rate) FROM vilsdt v1 WHERE v1.REF_NO=v.REF_NO)AS adjst" + ",sum(p.CASH_AMT) as cash," + "sum(p.CARD_AMT) as card,sum(p.BANK_AMT) as bank,sum(p.BAJAJ_AMT) as bajaj" + " from VILSHD v left join PAYMENT p on v.REF_NO=p.REF_NO where is_del =0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "'"; if (mode != 2) { sql += " and v.V_TYPE=" + mode; } if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("ins", viewDataRs.getDouble("ins")); object.addProperty("net_amt", viewDataRs.getDouble("net_amt")); object.addProperty("buy_back", viewDataRs.getDouble("buy_back")); object.addProperty("cash", viewDataRs.getDouble("cash")); object.addProperty("card", viewDataRs.getString("card")); object.addProperty("bank", viewDataRs.getString("bank")); object.addProperty("bajaj", viewDataRs.getString("bajaj")); object.addProperty("adjst", viewDataRs.getString("adjst")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.GenralLedger.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j av a 2s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DBHelper helper = DBHelper.GetDBHelper(); dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); ac_cd = request.getParameter("ac_cd"); from_date = request.getParameter("from_date"); to_date = request.getParameter("to_date"); try { if (dataConnection != null) { double opb = 0.00; String sql = "(select (select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' and DOC_DATE<'" + from_date + "' and CRDR=0) -" + "(select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' " + "and DOC_DATE<'" + from_date + "' and CRDR=1) as opb from dual) "; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); viewDataRS = pstLocal.executeQuery(); if (viewDataRS.next()) { jResultObj.addProperty("opb", viewDataRS.getDouble("opb")); opb = viewDataRS.getDouble("opb"); } else { jResultObj.addProperty("opb", 0.00); } makeQuery(); double opbRs = 0.00; JsonArray array = new JsonArray(); while (viewDataRS.next()) { JsonObject object = new JsonObject(); object.addProperty("FNAME", viewDataRS.getString("FNAME")); if (viewDataRS.getString("DOC_REF_NO").startsWith("05")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("BILL_NO")); } else if (viewDataRS.getString("DOC_REF_NO").startsWith("02")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); } else if (viewDataRS.getString("INV_NO").equalsIgnoreCase("0")) { object.addProperty("DOC_REF_NO", viewDataRS.getString("DOC_REF_NO")); } else { object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); } object.addProperty("DOC_DATE", viewDataRS.getString("DOC_DATE")); object.addProperty("DOC_CD", viewDataRS.getString("DOC_CD")); object.addProperty("DR", lb.roundOffDoubleValue(viewDataRS.getDouble("DR"))); object.addProperty("CR", lb.roundOffDoubleValue(viewDataRS.getDouble("CR"))); opbRs += viewDataRS.getDouble("DR") - viewDataRS.getDouble("CR"); object.addProperty("BAL", lb.roundOffDoubleValue(opbRs)); object.addProperty("PARTICULAR", viewDataRS.getString("PARTICULAR")); object.addProperty("OPP_AC_CD", viewDataRS.getString("OPP_AC_CD")); object.addProperty("REF_NO", viewDataRS.getString("doc_ref_no")); object.addProperty("OPB", opb); array.add(object); } jResultObj.addProperty("opb", opb); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } response.getWriter().print(jResultObj); }
From source file:account.GetCardDetail.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a va 2 s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select v.ref_no,v_date,inv_no,a.FNAME,v.NET_AMT,p.CARD_AMT,p.tid_no,p.card_no from vilshd v,payment p,acntmst a, phbkmst p1\n" + " where v.AC_CD=a.AC_CD and v.REF_NO=p.REF_NO and a.AC_CD = p1.AC_CD and v.IS_DEL=0 and v.v_date>='" + from_date + "' " + " and v.v_date <='" + to_date + "' and card_amt <>0"; if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("ref_no", viewDataRs.getString("ref_no")); object.addProperty("v_date", viewDataRs.getString("v_date")); object.addProperty("inv_no", viewDataRs.getString("inv_no")); object.addProperty("fname", viewDataRs.getString("fname")); object.addProperty("net_amt", viewDataRs.getString("net_amt")); object.addProperty("card_amt", viewDataRs.getString("card_amt")); object.addProperty("tid_no", viewDataRs.getString("tid_no")); object.addProperty("card_no", viewDataRs.getString("card_no")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.GetDenomation.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w.ja va 2s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String from_date = request.getParameter("v_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select * from denomation where v_date='" + from_date + "'"; if (branch_cd != 0) { sql += " and branch_cd=" + branch_cd; } pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("note_cd", viewDataRs.getInt("note_cd")); object.addProperty("qty", viewDataRs.getInt("qty")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.GetGeneralLedgerSummary.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w.j a v a 2s .com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DBHelper helper = DBHelper.GetDBHelper(); dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); ac_cd = request.getParameter("ac_cd"); from_date = request.getParameter("from_date"); to_date = request.getParameter("to_date"); try { if (dataConnection != null) { makeQuery(); JsonArray array = new JsonArray(); while (crsMain.next()) { JsonObject object = new JsonObject(); object.addProperty("MONTH", crsMain.getString("MONTH")); object.addProperty("DR", crsMain.getDouble("DR")); object.addProperty("CR", crsMain.getDouble("CR")); object.addProperty("AMT", crsMain.getDouble("AMT")); array.add(object); } jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } response.getWriter().print(jResultObj); }
From source file:account.GetGroupSummary.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a v a 2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String grp_cd = request.getParameter("grp_cd"); final double amt = Double.parseDouble(request.getParameter("amt")); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final int mode = Integer.parseInt(request.getParameter("mode")); Library lb = Library.getInstance(); if (dataConnection != null) { try { String sql = null; PreparedStatement pstLocal = null; sql = "select concat(fname , ' ' ,mname , ' ' , lname) as fname,opb,"; for (int i = 1; i <= 12; i++) { sql += "DR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += " as dr, "; for (int i = 1; i <= 12; i++) { sql += "CR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += " as cr ,("; for (int i = 1; i <= 12; i++) { sql += "DR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += "-"; for (int i = 1; i <= 12; i++) { sql += "CR_" + i + "-"; } sql = sql.substring(0, sql.length() - 1); sql += ") as bal,acntmst.ac_cd from oldb2_1,acntmst,GROUPMST " + "where ACNTMST.GRP_CD=GROUPMST.grp_cd and (("; for (int i = 1; i <= 12; i++) { sql += "DR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += "-"; for (int i = 1; i <= 12; i++) { sql += "CR_" + i + "-"; } sql = sql.substring(0, sql.length() - 1); sql += ") > 1 or ("; for (int i = 1; i <= 12; i++) { sql += "DR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += "-"; for (int i = 1; i <= 12; i++) { sql += "CR_" + i + "-"; } sql = sql.substring(0, sql.length() - 1); sql += ") < -1 )"; if (!grp_cd.equalsIgnoreCase("")) { sql += "and (ACNTMST.grp_cd='" + grp_cd + "' " + "or acntmst.grp_cd in( select grp_cd from groupmst where head_grp='" + grp_cd + "')) "; } sql += " and acntmst.ac_cd=oldb2_1.ac_cd and ("; for (int i = 1; i <= 12; i++) { sql += "DR_" + i + "+"; } sql = sql.substring(0, sql.length() - 1); sql += "-"; for (int i = 1; i <= 12; i++) { sql += "CR_" + i + "-"; } sql = sql.substring(0, sql.length() - 1); if (mode == 0) { sql += ") <> 0"; } else if (mode == 1) { sql += " ) <" + (amt * -1); } else if (mode == 2) { sql += " ) >" + amt; } sql += " order by fname"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("fname", viewDataRs.getString("fname")); object.addProperty("opb", viewDataRs.getDouble("opb")); object.addProperty("dr", viewDataRs.getDouble("dr")); object.addProperty("cr", viewDataRs.getDouble("cr")); object.addProperty("bal", viewDataRs.getDouble("bal")); object.addProperty("ac_cd", viewDataRs.getString("ac_cd")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }