List of usage examples for com.google.gson JsonArray JsonArray
public JsonArray()
From source file:EAIJSONConverter.java
License:Open Source License
public JsonObject traversePS(SiebelPropertySet ps, JsonObject jObj) { JsonObject siebJSON = new JsonObject(); String propName;// ww w . j av a 2 s . c om String propVal; propName = ps.getFirstProperty(); while (propName != "") { propVal = ps.getProperty(propName); siebJSON.addProperty(propName, propVal); propName = ps.getNextProperty(); } JsonObject child; for (int i = 0; i < ps.getChildCount(); i++) { child = new JsonObject(); if (ps.getChild(i).getType().startsWith("ListOf-")) { JsonArray ja = new JsonArray(); for (int o = 0; o < ps.getChild(i).getChildCount(); o++) { ja.add(traversePS(ps.getChild(i).getChild(o), child)); } siebJSON.add(ps.getChild(i).getType().substring(7), ja); } else if (ps.getChild(i).getType().startsWith("StringList-")) { JsonArray ja = new JsonArray(); SiebelPropertySet auxps = ps.getChild(i); Enumeration e = auxps.getPropertyNames(); List list = Collections.list(e); Collections.sort(list); e = Collections.enumeration(list); while (e.hasMoreElements()) { String propName1 = (String) e.nextElement(); ja.add(new JsonPrimitive(auxps.getProperty(propName1))); } siebJSON.add(auxps.getType().substring(11), ja); } else { child = traversePS(ps.getChild(i), child); siebJSON.add(ps.getChild(i).getType(), child); } } return siebJSON; }
From source file:CustomAudienceExample.java
License:Open Source License
public static void main(String[] args) { try {/* ww w. j av a 2 s . c o m*/ AdAccount account = new AdAccount(ACCOUNT_ID, context); CustomAudience audience = account.createCustomAudience().setName("Java SDK Test Custom Audience") .setDescription("Test Audience").setSubtype(EnumSubtype.VALUE_CUSTOM).execute(); // Audience payload schema JsonArray schema = new JsonArray(); schema.add(new JsonPrimitive("EMAIL_SHA256")); schema.add(new JsonPrimitive("PHONE_SHA256")); // Audience payload data JsonArray personA = new JsonArray(); personA.add(new JsonPrimitive(sha256("aaa@example.com"))); personA.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personB = new JsonArray(); personB.add(new JsonPrimitive(sha256("bbb@example.com"))); personB.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personC = new JsonArray(); personC.add(new JsonPrimitive(sha256("ccc@example.com"))); personC.add(new JsonPrimitive(sha256("1234567890"))); JsonArray data = new JsonArray(); data.add(personA); data.add(personB); data.add(personC); JsonObject payload = new JsonObject(); payload.add("schema", schema); payload.add("data", data); audience.createUser().setPayload(payload.toString()).execute(); System.out.println(audience.fetch()); Targeting targeting = new Targeting().setFieldCustomAudiences("[{id:" + audience.getId() + "}]"); Campaign campaign = account.createCampaign().setName("Java SDK Test Campaign") .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS).setSpendCap(10000L) .setStatus(Campaign.EnumStatus.VALUE_PAUSED).execute(); AdSet adset = account.createAdSet().setName("Java SDK Test AdSet").setCampaignId(campaign.getFieldId()) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS).setDailyBudget(1000L) .setBidAmount(100L).setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_IMPRESSIONS) .setTargeting(targeting).setRedownload(true).requestAllFields().execute(); System.out.println(adset); AdImage image = account.createAdImage().addUploadFile("file", imageFile).execute(); AdCreative creative = account.createAdCreative().setTitle("Java SDK Test Creative") .setBody("Java SDK Test Creative").setImageHash(image.getFieldHash()) .setLinkUrl("www.facebook.com").setObjectUrl("www.facebook.com").execute(); Ad ad = account.createAd().setName("Java SDK Test ad").setAdsetId(Long.parseLong(adset.getId())) .setCreative(creative).setStatus("PAUSED").setBidAmount(100L).setRedownload(true).execute(); } catch (APIException e) { e.printStackTrace(); } }
From source file:account.BajajReport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . 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 String ac_cd = request.getParameter("ac_cd"); 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 { String sql = "select v1.v_type,v1.branch_cd,v.ref_no,v1.inv_no,a.FNAME,s.SR_NAME,v1.V_DATE as ins_date,v.TAG_NO,p.BAJAJ_AMT,p.SFID,a1.fname as bajaj_name from vilsdt v " + " left join SERIESMST s on v.SR_CD=s.SR_CD left join VILSHD v1 on v.REF_NO=v1.REF_NO left join acntmst a on v1.AC_CD=a.AC_CD " + " left join payment p on v1.ref_no=p.ref_no left join acntmst a1 on p.bajaj_name=a1.ac_cd " + " where v1.V_DATE>='" + from_date + "'" + " and v1.V_DATE<='" + to_date + "' and v1.is_del=0 and p.bajaj_amt <>0 " + " and (v.IMEI_NO<>'' or v.SERAIL_NO<>'') and v.is_main=1"; if (branch_cd != 0) { sql += " and v1.branch_cd=" + branch_cd; } if (!ac_cd.equalsIgnoreCase("")) { sql += " and p.bajaj_name='" + ac_cd + "'"; } sql += " order by v1.V_DATE"; PreparedStatement 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("SR_NAME", viewDataRs.getString("SR_NAME")); object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO")); object.addProperty("INS_DATE", viewDataRs.getString("ins_date")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); object.addProperty("RATE", viewDataRs.getDouble("BAJAJ_AMT")); object.addProperty("REF_NO", viewDataRs.getString("REF_NO")); object.addProperty("SFID", viewDataRs.getString("SFID")); object.addProperty("BAJAJ_NAME", viewDataRs.getString("BAJAJ_NAME")); 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.BankBook.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j av a 2 s. 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"); rec_date = Boolean.parseBoolean(request.getParameter("rec_date")); from_date = request.getParameter("from_date"); to_date = request.getParameter("to_date"); try { if (dataConnection != null) { makeQuery(); double opbRs = 0.00; JsonArray array = new JsonArray(); while (viewDataRS.next()) { JsonObject object = new JsonObject(); object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); object.addProperty("DOC_DATE", viewDataRS.getString("DOC_DATE")); object.addProperty("REC_DATE", viewDataRS.getString("REC_DATE")); object.addProperty("DOC_CD", viewDataRS.getString("DOC_CD")); object.addProperty("DR", viewDataRS.getDouble("DR")); object.addProperty("CR", viewDataRS.getDouble("CR")); opbRs += viewDataRS.getDouble("DR") - viewDataRS.getDouble("CR"); object.addProperty("BAL", opbRs); object.addProperty("PARTICULAR", viewDataRS.getString("PARTICULAR")); object.addProperty("OPP_AC_CD", viewDataRS.getString("OPP_AC_CD")); object.addProperty("REC_DATE", viewDataRS.getString("REC_DATE")); object.addProperty("OPP_NAME", viewDataRS.getString("OPP_NAME")); object.addProperty("REF_NO", viewDataRS.getString("doc_ref_no")); object.addProperty("CHQ_NO", viewDataRS.getString("CHQ_NO")); object.addProperty("REC_BANK_NAME", viewDataRS.getString("REC_BANK_NAME")); array.add(object); } 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 (REC_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 (REC_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")); } else { jResultObj.addProperty("opb", 0.00); } 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.BranchWisePendingCollecionReport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w. j av 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 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 int v_type = Integer.parseInt(request.getParameter("v_type")); final String ref_cd = (request.getParameter("ref_cd")); final Library lb = Library.getInstance(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "SELECT p.mobile1,v.REMARK,v.INV_NO,o.DOC_REF_NO,o.DOC_DATE,o.AC_CD,o.UNPAID_AMT,o.DUE_DATE,v.BRANCH_CD,a.FNAME,v.buy_back_model,v.buy_back_amt,r.ref_name FROM " + "oldb2_4 o LEFT JOIN vilshd v ON v.REF_NO=o.DOC_REF_NO LEFT JOIN acntmst a ON a.AC_CD=v.AC_CD " + " left join refmst r on v.ref_cd=r.ref_cd left join phbkmst p on a.ac_cd=p.ac_cd" + " WHERE doc_ref_no LIKE '02%' AND o.UNPAID_AMT >0 and v.is_del=0 "; if (branch_cd != 0) { sql += " and v.branch_cd=" + branch_cd; } if (v_type != -1) { sql += " and v.v_type=" + v_type; } if (!ref_cd.equalsIgnoreCase("0")) { sql += " and v.REF_CD='" + ref_cd + "'"; } pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("DOC_DATE", viewDataRs.getString("DOC_DATE")); object.addProperty("INV_NO", viewDataRs.getString("INV_NO")); object.addProperty("DOC_REF_NO", viewDataRs.getString("DOC_REF_NO")); object.addProperty("AC_CD", viewDataRs.getString("AC_CD")); object.addProperty("DOC_CD", ""); object.addProperty("UNPAID_AMT", viewDataRs.getDouble("UNPAID_AMT")); object.addProperty("DUE_DATE", viewDataRs.getString("DUE_DATE")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); object.addProperty("FNAME", viewDataRs.getString("FNAME")); object.addProperty("BUY_BACK_MODEL", viewDataRs.getString("BUY_BACK_MODEL")); object.addProperty("BUY_BACK_AMT", viewDataRs.getString("BUY_BACK_AMT")); object.addProperty("REMARK", viewDataRs.getString("REMARK")); object.addProperty("MOBILE1", (viewDataRs.getString("MOBILE1") == null) ? "" : viewDataRs.getString("MOBILE1")); object.addProperty("REF_NAME", (viewDataRs.getString("REF_NAME") == null) ? "" : viewDataRs.getString("REF_NAME")); 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.BuyBackRegister.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w w w .j a v a 2 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 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 v.branch_cd,v.inv_no,v.ref_no,a.fname,v.BUY_BACK_MODEL,v.v_date,'' as TYPE_NAME,BUY_BACK_MODEL as IMEI_NO,BUY_BACK_IMEI_NO,(1) as pcs,BUY_BACK_AMT as tot_sales from VILSHD v " + " left join acntmst a on v.ac_cd=a.ac_cd where v.IS_DEL=0 " + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date + "' and v.BUY_BACK_AMT <> 0"; 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 v.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("BUY_BACK_MODEL")); object.addProperty("v_date", viewDataRs.getString("v_date")); object.addProperty("type_name", viewDataRs.getString("type_name")); object.addProperty("pcs", viewDataRs.getInt("pcs")); object.addProperty("tot_sales", viewDataRs.getDouble("tot_sales")); object.addProperty("IMEI_NO", viewDataRs.getString("IMEI_NO")); object.addProperty("BUY_BACK_IMEI_NO", viewDataRs.getString("BUY_BACK_IMEI_NO")); object.addProperty("REF_NO", viewDataRs.getString("REF_NO")); object.addProperty("INV_NO", viewDataRs.getString("INV_NO")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); 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.CardWiseSalesDetailStatement.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j av a 2 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 ac_cd = request.getParameter("ac_cd"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select v.ins_amt,v.ref_no,case when v.V_TYPE=0 then 'Retail Invoice' else 'Tax Invoice' end as v_type,v.INV_NO,v.V_DATE,v.PMT_MODE," + " case when a.FNAME is null then '' else fname end as fname,s.SR_ALIAS,s.SR_NAME,v1.IMEI_NO," + " v1.SERAIL_NO,v1.QTY,v1.RATE,v1.AMT,v.DET_TOT,v1.TAX_AMT,v1.ADD_TAX_AMT,v.NET_AMT,p.CASH_AMT,p.BANK_AMT,p.CARD_AMT,p.bajaj_amt,t.TAX_NAME" + " ,v.BUY_BACK_MODEL,v.BUY_BACK_AMT from VILSHD v left join VILSDT v1 on v.REF_NO =v1.REF_NO left join acntmst a on v.AC_CD=a.AC_CD " + " left join SERIESMST s on s.SR_CD=v1.SR_CD left join PAYMENT p on v.REF_NO=p.REF_NO left join TAXMST t on v1.TAX_CD=t.TAX_CD " + " where is_del=0 and card_no<>''"; if (!ac_cd.equalsIgnoreCase("")) { sql += " and v.ac_cd='" + ac_cd + "' "; } sql += " order by v.V_DATE,v.INV_NO"; 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_type", viewDataRs.getString("V_TYPE")); object.addProperty("inv_no", viewDataRs.getString("inv_no")); object.addProperty("fname", viewDataRs.getString("FNAME")); object.addProperty("SR_ALIAS", viewDataRs.getString("SR_ALIAS")); object.addProperty("SR_NAME", viewDataRs.getString("SR_NAME")); object.addProperty("IMEI_NO", viewDataRs.getString("IMEI_NO")); object.addProperty("SERAIL_NO", viewDataRs.getString("SERAIL_NO")); object.addProperty("v_date", viewDataRs.getString("V_DATE")); object.addProperty("QTY", viewDataRs.getInt("QTY")); object.addProperty("RATE", viewDataRs.getDouble("RATE")); object.addProperty("AMT", viewDataRs.getDouble("AMT")); object.addProperty("det_tot", viewDataRs.getDouble("DET_TOT")); object.addProperty("tax_amt", viewDataRs.getDouble("TAX_AMT")); object.addProperty("add_tax_amt", viewDataRs.getDouble("ADD_TAX_AMT")); object.addProperty("CASH_AMT", viewDataRs.getDouble("CASH_AMT")); object.addProperty("BANK_AMT", viewDataRs.getDouble("BANK_AMT")); object.addProperty("CARD_AMT", viewDataRs.getDouble("CARD_AMT")); object.addProperty("net_amt", viewDataRs.getDouble("NET_AMT")); object.addProperty("tax_name", viewDataRs.getString("tax_name")); object.addProperty("buy_back_model", viewDataRs.getString("buy_back_model")); object.addProperty("ins_amt", viewDataRs.getDouble("ins_amt")); object.addProperty("buy_back_amt", viewDataRs.getDouble("buy_back_amt")); object.addProperty("bajaj_amt", viewDataRs.getDouble("bajaj_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()); } } response.getWriter().print(jResultObj); }
From source file:account.CardWiseSalesStatement.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . j av a 2s . 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 DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final boolean card_no = Boolean.parseBoolean(request.getParameter("card").toString()); if (dataConnection != null) { try { PreparedStatement pstLocal = null; String sql = "select a.AC_CD,a.FNAME,a.CARD_NO,p.MOBILE1,sum(v.DET_TOT+v.TAX_AMT+v.ADD_TAX_AMT) as NET_AMT from VILSHD v " + " left join ACNTMST a on v.AC_CD=a.AC_CD left join phbkmst p on p.AC_CD=a.AC_CD " + " where v.IS_DEL=0 "; if (!card_no) { sql += " and CARD_NO <>''"; } sql += " group by a.FNAME,a.card_no,a.ac_cd,p.mobile1 order by a.CARD_NO"; pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("AC_CD", viewDataRs.getString("AC_CD")); object.addProperty("FNAME", viewDataRs.getString("FNAME")); object.addProperty("CARD_NO", viewDataRs.getString("CARD_NO")); object.addProperty("MOBILE1", viewDataRs.getString("MOBILE1")); object.addProperty("NET_AMT", viewDataRs.getDouble("NET_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()); } } response.getWriter().print(jResultObj); }
From source file:account.CashSnapshot.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . ja 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 grp_cd = request.getParameter("grp_cd"); String from_date = ""; String to_date = ""; from_date = request.getParameter("from_date"); to_date = request.getParameter("to_date"); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); Library lb = Library.getInstance(); if (dataConnection != null) { try { String sql = null; PreparedStatement pstLocal = null; sql = "SELECT o.ac_cd,fname,doc_date,SUM(CASE WHEN crdr=0 THEN val ELSE 0 END) AS dr,SUM(CASE WHEN crdr=1 THEN val ELSE 0 END) AS cr," + " (SUM(CASE WHEN crdr=0 THEN val ELSE 0 END) -SUM(CASE WHEN crdr=1 THEN val ELSE 0 END)) AS bal" + " FROM oldb2_2 o left join acntmst a on a.ac_cd=o.ac_cd WHERE o.ac_cd IN (SELECT ac_cd FROM acntmst WHERE grp_cd ='" + grp_cd + "')" + " AND doc_date>='" + from_date + "' and doc_date<='" + to_date + "' GROUP BY o.ac_cd,fname,doc_date"; 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("doc_date", viewDataRs.getString("doc_date")); 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); }
From source file:account.CreditNoteRegister.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www. ja va2 s .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("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 a.FNAME,s.SR_NAME,t.BASIC_PUR_RATE,t.PUR_RATE,t.TAG_NO,p.REMARK,l.V_DATE as PUR_DATE,v.V_DATE as SALE_DATE,p.RATE " + " from PRIZE_DROP p left join TAG t on p.PUR_TAG_NO=t.REF_NO left join SERIESMST s on t.SR_CD=s.SR_CD " + " left join LBRPHD l on t.PUR_REF_NO=l.REF_NO left join modelmst m on s.model_cd=m.model_cd " + " left join acntmst a on l.AC_CD=a.AC_CD left join VILSHD v on t.SALE_REF_NO=v.REF_NO where " + " p.v_date>='" + from_date + "' " + " and p.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 v.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("BASIC_PUR_RATE", viewDataRs.getDouble("BASIC_PUR_RATE")); object.addProperty("PUR_RATE", viewDataRs.getDouble("PUR_RATE")); object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO")); object.addProperty("REMARK", viewDataRs.getString("REMARK")); object.addProperty("PUR_DATE", viewDataRs.getString("PUR_DATE")); object.addProperty("SALE_DATE", viewDataRs.getString("SALE_DATE")); object.addProperty("RATE", viewDataRs.getString("RATE")); 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); }