Example usage for com.google.gson JsonObject addProperty

List of usage examples for com.google.gson JsonObject addProperty

Introduction

In this page you can find the example usage for com.google.gson JsonObject addProperty.

Prototype

public void addProperty(String property, Character value) 

Source Link

Document

Convenience method to add a char member.

Usage

From source file:account.UpdateBill.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w  w .  jav  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 DBHelper helper = DBHelper.GetDBHelper();
    final Library lb = Library.getInstance();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    final String dr_doc_ref_no = (request.getParameter("dr_doc_ref_no"));
    final String cr_doc_ref_no = (request.getParameter("cr_doc_ref_no"));
    final String dr_doc_cd = (request.getParameter("DR_DOC_CD"));
    final String cr_doc_cd = (request.getParameter("CR_DOC_CD"));
    final String dr_inv_no = (request.getParameter("DR_INV_NO"));
    final String cr_inv_no = (request.getParameter("CR_INV_NO"));
    final double dr_amt = Double.parseDouble(request.getParameter("DR_AMT"));
    final double cr_amt = Double.parseDouble(request.getParameter("CR_AMT"));
    final int dr_sr_no = (int) Double.parseDouble(request.getParameter("DR_SR_NO"));
    final int cr_sr_no = (int) Double.parseDouble(request.getParameter("CR_SR_NO"));
    if (dataConnection != null) {
        try {
            dataConnection.setAutoCommit(false);
            PreparedStatement pstLocal = null;
            String sql = "update oldb2_4 set UNPAID_AMT=UNPAID_AMT-? where DOC_REF_NO=?";
            pstLocal = dataConnection.prepareStatement(sql);
            if (dr_amt + cr_amt >= 0) {
                pstLocal.setDouble(1, cr_amt * -1);
            } else {
                pstLocal.setDouble(1, dr_amt);
            }
            pstLocal.setString(2, dr_doc_ref_no);
            pstLocal.executeUpdate();

            sql = "update oldb2_4 set UNPAID_AMT=UNPAID_AMT+? where DOC_REF_NO=?";
            pstLocal = dataConnection.prepareStatement(sql);
            if (dr_amt + cr_amt >= 0) {
                pstLocal.setDouble(1, cr_amt * -1);
            } else {
                pstLocal.setDouble(1, dr_amt);
            }
            pstLocal.setString(2, cr_doc_ref_no);
            pstLocal.executeUpdate();

            sql = "INSERT INTO billadjst (doc_ref_no,DR_DOC_REF_NO,CR_DOC_REF_NO,DR_DOC_CD,CR_DOC_CD,DR_INV_NO,CR_INV_NO,AMT,dr_sr_no,cr_sr_no) values(?,?,?,?,?,?,?,?,?,?)";
            pstLocal = dataConnection.prepareStatement(sql);
            pstLocal.setString(1, lb.generateKey(dataConnection, "billadjst", "DOC_REF_NO", "BI", 7));
            pstLocal.setString(2, dr_doc_ref_no);
            pstLocal.setString(3, cr_doc_ref_no);
            pstLocal.setString(4, dr_doc_cd);
            pstLocal.setString(5, cr_doc_cd);
            pstLocal.setString(6, dr_inv_no);
            pstLocal.setString(7, cr_inv_no);
            pstLocal.setDouble(8, (dr_amt >= Math.abs(cr_amt)) ? Math.abs(cr_amt) : dr_amt);
            pstLocal.setInt(9, dr_sr_no);
            pstLocal.setInt(10, cr_sr_no);
            pstLocal.executeUpdate();

            dataConnection.commit();
            dataConnection.setAutoCommit(true);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (Exception e) {

            }
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (Exception e) {

            }
        } finally {
            lb.closeConnection(dataConnection);
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:account.updateDenomation.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w  w.jav  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 Library lb = Library.getInstance();
    final String v_date = request.getParameter("v_date");
    final String branch_cd = request.getParameter("branch_cd");
    final String note_cd = request.getParameter("note_cd");
    final String qty = request.getParameter("qty");
    final DBHelper helper = DBHelper.GetDBHelper();
    final JsonObject jResultObj = new JsonObject();
    final Connection dataConnection = helper.getConnMpAdmin();
    if (dataConnection != null) {
        try {
            String sql = "delete from denomation where v_date=? and branch_cd=? and note_cd=?";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            pstLocal.setString(1, v_date);
            pstLocal.setString(2, branch_cd);
            pstLocal.setString(3, note_cd);
            pstLocal.executeUpdate();

            sql = "insert into denomation (v_date,branch_cd,note_cd,qty) values (?,?,?,?)";
            pstLocal = dataConnection.prepareStatement(sql);
            pstLocal.setString(1, v_date);
            pstLocal.setString(2, branch_cd);
            pstLocal.setString(3, note_cd);
            pstLocal.setString(4, qty);
            pstLocal.executeUpdate();

            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } 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.UpdateNlc.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from ww 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 detailJson = request.getParameter("detail");
    TypeToken<List<NlcModel>> token = new TypeToken<List<NlcModel>>() {
    };
    final List<NlcModel> detail = new Gson().fromJson(detailJson, token.getType());
    final ArrayList<NlcModel> data = (ArrayList<NlcModel>) detail;
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final Library lb = Library.getInstance();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {
            dataConnection.setAutoCommit(false);
            PreparedStatement pstUpdate1 = null;
            String sql1 = "update tag set disc_per=?,extra_support=?,backend=?,activation=?,prize_drop=? where ref_no=?";
            pstUpdate1 = dataConnection.prepareStatement(sql1);
            for (int i = 0; i < data.size(); i++) {
                pstUpdate1.setDouble(1, data.get(i).getDisc_per());
                pstUpdate1.setDouble(2, data.get(i).getExtra_support());
                pstUpdate1.setDouble(3, data.get(i).getBackend());
                pstUpdate1.setDouble(4, data.get(i).getActivation());
                pstUpdate1.setDouble(5, data.get(i).getPrize_drop());
                pstUpdate1.setString(6, data.get(i).getRef_no());
                pstUpdate1.executeUpdate();
            }

            String sql = "update oldb2_1 set dr_" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "=dr_"
                    + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "+? where ac_CD=?";
            PreparedStatement pstUpdate = dataConnection.prepareStatement(sql);
            pstUpdate.setDouble(1, data.get(0).getCnAmount());
            pstUpdate.setString(2, data.get(0).getAc_cd());
            pstUpdate.executeUpdate();

            sql = "insert into oldb2_2 (doc_ref_no,doc_date,doc_cd,ac_cd,"
                    + "val,crdr,particular,opp_ac_cd,time_stamp,INV_NO) values(?,CURRENT_DATE,?,?,?,?,?,?,CURRENT_TIMESTAMP,?)";

            pstUpdate = dataConnection.prepareStatement(sql);
            pstUpdate.setString(1, "PD");
            pstUpdate.setString(2, "PD");
            pstUpdate.setString(3, data.get(0).getAc_cd());
            pstUpdate.setDouble(4, data.get(0).getCnAmount());
            pstUpdate.setString(5, "0");
            pstUpdate.setString(6, data.get(0).getRemark());
            pstUpdate.setString(7, "");
            pstUpdate.setString(8, "0");
            pstUpdate.executeUpdate();

            sql = "insert into prize_drop (pur_tag_no,sr_no,voucher_no,v_date,remark,prev_rate,rate,ac_cd) values (?,?,?,CURRENT_DATE,?,?,?,?)";
            pstUpdate = dataConnection.prepareStatement(sql);
            for (int i = 0; i < data.size(); i++) {
                pstUpdate.setString(1, data.get(i).getRef_no());
                pstUpdate.setInt(2, i + 1);
                pstUpdate.setString(3, lb.generateKey(dataConnection, "prize_drop", "voucher_no", "PZ", 7));
                pstUpdate.setString(4, data.get(i).getRemark());
                pstUpdate.setDouble(5, 0.00);
                pstUpdate.setDouble(6, data.get(i).getExtra_support() + data.get(i).getBackend()
                        + data.get(i).getBackend() + data.get(i).getActivation() + data.get(i).getPrize_drop());
                pstUpdate.setString(7, data.get(i).getAc_cd());
                pstUpdate.executeUpdate();
            }
            dataConnection.commit();
            dataConnection.setAutoCommit(true);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(UpdatePrize.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (SQLException ex2) {
                Logger.getLogger(UpdatePrize.class.getName()).log(Level.SEVERE, null, ex2);
            }
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.UpdateOLDB2_4.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w  ww .ja  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 unpaid_amt = request.getParameter("unpaid_amt");
    final String doc_ref_no = request.getParameter("doc_ref_no");
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {

            PreparedStatement pstLocal = null;
            String sql = "UPDATE oldb2_4 SET unpaid_amt=? WHERE doc_ref_no=?";
            pstLocal = dataConnection.prepareStatement(sql);
            pstLocal.setString(1, unpaid_amt);
            pstLocal.setString(2, doc_ref_no);
            pstLocal.executeUpdate();
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } 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.UpdatePrize.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  ww . ja  v a2s. 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 detailJson = request.getParameter("detail");
    TypeToken<List<PrizeDrop>> token = new TypeToken<List<PrizeDrop>>() {
    };
    final List<PrizeDrop> detail = new Gson().fromJson(detailJson, token.getType());
    final ArrayList<PrizeDrop> data = (ArrayList<PrizeDrop>) detail;
    final DBHelper helper = DBHelper.GetDBHelper();
    final Connection dataConnection = helper.getConnMpAdmin();
    final Library lb = Library.getInstance();
    final JsonObject jResultObj = new JsonObject();
    if (dataConnection != null) {
        try {
            dataConnection.setAutoCommit(false);
            PreparedStatement pstLocal = null;
            PreparedStatement pstLocal1 = null;
            String sql = "insert into prize_drop (pur_tag_no,sr_no,voucher_no,v_date,remark,prev_rate,rate,ac_cd) values (?,?,?,CURRENT_DATE,?,?,?,?)";
            String sql1 = "update tag set pur_rate=pur_rate-? where ref_no=?";
            pstLocal = dataConnection.prepareStatement(sql);
            pstLocal1 = dataConnection.prepareStatement(sql1);
            for (int i = 0; i < data.size(); i++) {
                pstLocal.setString(1, data.get(i).getPur_tag_no());
                pstLocal.setInt(2, i + 1);
                if (data.get(i).getVoucher_no().equalsIgnoreCase("")) {
                    pstLocal.setString(3, lb.generateKey(dataConnection, "prize_drop", "voucher_no", "PZ", 7));
                } else {
                    pstLocal.setString(3, data.get(i).getVoucher_no());
                }
                pstLocal.setString(4, data.get(i).getRemark());
                pstLocal.setDouble(5, data.get(i).getPrevious_rate());
                pstLocal.setDouble(6, data.get(i).getRate());
                pstLocal.setString(7, data.get(i).getAc_cd());
                pstLocal.executeUpdate();

                pstLocal1.setDouble(1, data.get(i).getRate());
                pstLocal1.setString(2, data.get(i).getPur_tag_no());
                pstLocal1.executeUpdate();

                sql = "update oldb2_1 set dr_" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "=dr_"
                        + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "+? where ac_CD=?";
                PreparedStatement pstUpdate = dataConnection.prepareStatement(sql);
                pstUpdate.setDouble(1, data.get(i).getRate());
                pstUpdate.setString(2, data.get(i).getAc_cd());
                pstUpdate.executeUpdate();

                sql = "insert into oldb2_2 (doc_ref_no,doc_date,doc_cd,ac_cd,"
                        + "val,crdr,particular,opp_ac_cd,time_stamp,INV_NO) values(?,CURRENT_DATE,?,?,?,?,?,?,CURRENT_TIMESTAMP,?)";

                pstUpdate = dataConnection.prepareStatement(sql);
                pstUpdate.setString(1, "PD");
                pstUpdate.setString(2, "PD");
                pstUpdate.setString(3, data.get(i).getAc_cd());
                pstUpdate.setDouble(4, data.get(i).getRate());
                pstUpdate.setString(5, "0");
                pstUpdate.setString(6, data.get(i).getRemark());
                pstUpdate.setString(7, "");
                pstUpdate.setString(8, "0");
                pstUpdate.executeUpdate();
            }
            dataConnection.commit();
            dataConnection.setAutoCommit(true);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(UpdatePrize.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (SQLException ex2) {
                Logger.getLogger(UpdatePrize.class.getName()).log(Level.SEVERE, null, ex2);
            }
        }
    }
    response.getWriter().print(jResultObj);

}

From source file:account.WithoutTagSalesReport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w ww  .java 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 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.ref_no,a.fname,s.sr_name,v.v_date,t.TYPE_NAME,case when IMEI_NO ='' then SERAIL_NO else IMEI_NO end as IMEI_NO,(v1.qty) as pcs,(v1.RATE) as tot_sales from VILSHD v left join vilsdt v1 on v.REF_NO=v1.REF_NO "
                    + " left join SERIESMST s on v1.SR_CD=s.SR_CD left join acntmst a on v.ac_cd=a.ac_cd "
                    + " left join MODELMST m on s.MODEL_CD=m.MODEL_CD left join TYPEMST t on m.TYPE_CD=t.TYPE_CD where v.IS_DEL=0 "
                    + " and v.v_date>='" + from_date + "' " + " and v.v_date<='" + to_date
                    + "' and v1.PUR_TAG_NO=''";
            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("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("REF_NO", viewDataRs.getString("REF_NO"));
                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:accountMaster.AddUpdateAccountMaster.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w ww.  j  a v a  2s.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 String acString = request.getParameter("ac_model");
    final JsonObject jResultObj = new JsonObject();
    AccountMasterModel acc = new Gson().fromJson(acString, AccountMasterModel.class);
    try {
        dataConnection.setAutoCommit(false);
        acc = saveVoucher(dataConnection, acc);
        dataConnection.commit();
        dataConnection.setAutoCommit(true);
        jResultObj.addProperty("result", 1);
        jResultObj.addProperty("Cause", "success");
        jResultObj.addProperty("ac_cd", acc.getAC_CD());
    } catch (SQLNonTransientConnectionException ex1) {
        jResultObj.addProperty("result", -1);
        jResultObj.addProperty("Cause", "Server is down");
        try {
            dataConnection.rollback();
            dataConnection.setAutoCommit(true);
        } catch (SQLException e) {

        }
    } catch (SQLException ex) {
        jResultObj.addProperty("result", -1);
        jResultObj.addProperty("Cause", ex.getMessage());
        try {
            dataConnection.rollback();
            dataConnection.setAutoCommit(true);
        } catch (SQLException e) {

        }
    } catch (Exception ex) {
        jResultObj.addProperty("result", -1);
        jResultObj.addProperty("Cause", ex.getMessage());
        try {
            dataConnection.rollback();
            dataConnection.setAutoCommit(true);
        } catch (SQLException e) {

        }
    }
    response.getWriter().print(jResultObj);
}

From source file:accountMaster.GetAccountMaster.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww  w  .  j  a  va 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 String ac_name = request.getParameter("AC_NAME");
    Library lb = Library.getInstance();
    if (dataConnection != null) {
        try {
            String sql = "select a.OPB_AMT,a.OPB_EFF,a.AC_CD,FNAME,g.GROUP_NAME,g.GRP_CD,CST,TIN,a1.ADD1,p.MOBILE1,a.card_no,p.EMAIL,gst_no from ACNTMST a left join GROUPMST g on a.GRP_CD=g.GRP_CD \n"
                    + "left join ADBKMST a1 on a.AC_CD=a1.AC_CD left join PHBKMST p on a.AC_CD=p.AC_CD ";
            if (ac_name != null) {
                sql += " where fname like '%" + ac_name + "%'";
            }
            sql += " order by fname";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("AC_CD", rsLocal.getString("AC_CD"));
                object.addProperty("FNAME", rsLocal.getString("FNAME"));
                object.addProperty("GROUP_NAME", rsLocal.getString("GROUP_NAME"));
                object.addProperty("GRP_CD", rsLocal.getString("GRP_CD"));
                object.addProperty("CST", rsLocal.getString("CST"));
                object.addProperty("TIN", rsLocal.getString("TIN"));
                object.addProperty("ADD1", rsLocal.getString("ADD1"));
                object.addProperty("MOBILE1", rsLocal.getString("MOBILE1"));
                object.addProperty("EMAIL", rsLocal.getString("EMAIL"));
                object.addProperty("CARD_NO", rsLocal.getString("CARD_NO"));
                object.addProperty("OPB_AMT", rsLocal.getString("OPB_AMT"));
                object.addProperty("OPB_EFF", rsLocal.getString("OPB_EFF"));
                object.addProperty("GST_NO", rsLocal.getString("GST_NO"));
                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:actions.ActivitesAction.java

@Override
public String execute(HttpServletRequest request) {

    ServiceMetier sm = new ServiceMetier();

    List<Activite> la = null;
    if (sm != null) {
        la = sm.obtenirActivites();//from  w w  w.  j av a 2 s  . c om
    }
    if (la != null) {
        request.setAttribute("ListActivite", la);
    } else {
        request.setAttribute("ListActivite", "NULL");
    }

    JsonArray jsonListe = new JsonArray();

    for (Activite act : la) {
        JsonObject jsonActivite = new JsonObject();

        jsonActivite.addProperty("id", act.getId());
        jsonActivite.addProperty("denomination", act.getDenomination());

        jsonListe.add(jsonActivite);
    }

    //Objet JSON "conteneur"
    JsonObject container = new JsonObject();
    container.add("activites", jsonListe);

    //Serialisation & Ecriture sur le flux de sortie
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(container);

    return json;

}

From source file:Actions.ConnectionNonClientAction.java

@Override
public void execute(HttpServletRequest request, HttpServletResponse reponse) {

    // Session !!!
    HttpSession session = request.getSession(true);
    try {/*  w w w  .  j a v  a 2 s.c  o m*/
        request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(ConnectionNonClientAction.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("Je suisConnectionNonClient");

    String mdp = request.getParameter("mdp");
    System.out.println("Mor de passe :" + mdp);
    // attention lors de la conversion du mdp
    long mdpl = -123; // cette ID n'existe pas
    try {
        mdpl = Long.parseLong(mdp);
    } catch (NumberFormatException e) {
        System.out.println("Le mdp entr n'est pas un nb");
    }

    JsonObject jsonVelo = new JsonObject();
    Livreur l = null;
    try {
        l = ServiceMetier.connexionLivreur(mdpl);
        if (l.getTypeId().equals("drone")) {
            l = null;
        }
    } catch (Exception ex) {
        Logger.getLogger(ConnectionAction.class.getName()).log(Level.SEVERE, null, ex);
    }
    // si livreur trouv, enregistrement dans la session et l'objet Json est dit plein
    if (l != null) {
        // enregistrer le livreur pour la session
        session.setAttribute("livreur", l);
        System.out.println("Livreur trouv");
        jsonVelo.addProperty("plein", 1);
        int indexTiret = l.toString().indexOf(" -");
        int apresVeloIndex = l.toString().indexOf("Vlo : ") + 7;
        String nomComplet = l.toString().substring(apresVeloIndex, indexTiret);
        jsonVelo.addProperty("nomC", nomComplet);
        jsonVelo.addProperty("plein", 1);
    } else {
        System.out.println("Livreur pas trouv");
        jsonVelo.addProperty("plein", 0);
    }

    // envoi de l'objet Json
    reponse.setContentType("text/html;charset=UTF-8");
    PrintWriter out = null;
    try {
        out = reponse.getWriter();
    } catch (IOException ex) {
        Logger.getLogger(GetRestaurantsAction.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.println(jsonVelo);
    out.close();

}