Example usage for org.json.simple JSONArray toString

List of usage examples for org.json.simple JSONArray toString

Introduction

In this page you can find the example usage for org.json.simple JSONArray toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.Assignment4.Prod.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)/*  w  ww .  ja v a2 s  .c o  m*/
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (connect == null) {
        return "not connected";
    } else {
        String query = "Select * from product where product_id = ?";
        PreparedStatement prepstmt = connect.prepareStatement(query);
        prepstmt.setInt(1, id);
        ResultSet rs = prepstmt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map pMap = new LinkedHashMap();
            pMap.put("productID", rs.getInt("product_id"));
            pMap.put("name", rs.getString("name"));
            pMap.put("description", rs.getString("description"));
            pMap.put("quantity", rs.getInt("quantity"));
            productArr.add(pMap);
        }
        result = productArr.toString();

        return result;
    }

}

From source file:control.ParametrizacionServlets.EliminarAsociacionContrato.java

private void eliminarGrupoContratosAsociados(HttpServletRequest request, HttpServletResponse response) {

    try {/*w  w  w  . j  a v a  2  s. c o  m*/
        //Obtenemos los paramtros enviados
        Double codigo = Double.parseDouble(request.getParameter("contrato"));

        JSONArray respError = new JSONArray(); // uno significa que no hay error

        //Obtenemos La informacion del manager
        AsociacionContratos manager = new AsociacionContratos();

        //Almacenamos el error que pueda resultar
        respError = manager.Eliminar(codigo);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");

        for (Object jsonObject : respError) {

            response.getWriter().write(respError.toString());

        }

    } catch (Exception e) {

    }
}

From source file:ASSINGMENT4.ServletProducts.java

private String getResults(String query, String... params) {
    String result = new String();
    try (Connection conn = getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }/*from  www .  j  a va  2s.co  m*/
        ResultSet rs = pstmt.executeQuery();
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("product_id", rs.getInt("product_id"));
            productMap.put("product_name", rs.getString("product_name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();
    } catch (SQLException ex) {
        Logger.getLogger(ServletProducts.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result.replace("},", "},\n");
}

From source file:com.web.mavenproject6.controller.CameraController.java

@RequestMapping(value = "/plist", method = RequestMethod.GET)
public @ResponseBody String getPersonalName(@RequestParam("personalName") String personalName) {
    JSONArray ar = new JSONArray();

    List<personal> pList = personalService.getAll();
    for (personal p : pList) {
        String a = p.getAccessNumber() + " " + p.getFname() + " " + p.getSname() + " " + p.getTname();
        if (a.contains(personalName)) {
            ar.add(p.toString());/*from  ww w.  ja  v a2s.  c o  m*/
        }
    }
    return ar.toString();

}

From source file:com.Assignment4.Assign.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *//*from w  w  w . ja v a 2s .c  o  m*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (connected == null) {
        return "not connected";
    } else {
        String query = "Select * from product";
        PreparedStatement ps = connected.prepareStatement(query);
        ResultSet rs = ps.executeQuery();
        String res = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map proMap = new LinkedHashMap();
            proMap.put("productID", rs.getInt("product_id"));
            proMap.put("name", rs.getString("name"));
            proMap.put("description", rs.getString("description"));
            proMap.put("quantity", rs.getInt("quantity"));
            productArr.add(proMap);
        }
        res = productArr.toString();
        return res.replace("},", "},\n");
    }

}

From source file:com.products.products.java

private String getResults(String query, String... params) {
    String result = new String();
    try (Connection conn = getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }/*  ww w. j av a2s .co  m*/
        ResultSet rs = pstmt.executeQuery();
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("productID"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();
    } catch (SQLException ex) {
        Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result.replace("},", "},\n");
}

From source file:com.Assignment4.Assign.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)/*from   w w  w .  j a v a  2s .  com*/
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (connected == null) {
        return "not connected";
    } else {
        String query = "Select * from product where product_id = ?";
        PreparedStatement pstmt = connected.prepareStatement(query);
        pstmt.setInt(1, id);
        ResultSet rs = pstmt.executeQuery();
        String res = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map proMap = new LinkedHashMap();
            proMap.put("productID", rs.getInt("product_id"));
            proMap.put("name", rs.getString("name"));
            proMap.put("description", rs.getString("description"));
            proMap.put("quantity", rs.getInt("quantity"));
            productArr.add(proMap);
        }
        res = productArr.toString();

        return res;
    }

}

From source file:com.product.Product.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)/*  w  ww.j a  v a 2  s .  co  m*/
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (connect == null) {
        return "not connected";
    } else {
        String query = "Select * from products where product_id = ?";
        PreparedStatement prepstmnt = connect.prepareStatement(query);
        prepstmnt.setInt(1, id);
        ResultSet rs = prepstmnt.executeQuery();
        String result = "";
        JSONArray prodArr = new JSONArray();
        while (rs.next()) {
            Map prodMap = new LinkedHashMap();
            prodMap.put("productID", rs.getInt("product_id"));
            prodMap.put("name", rs.getString("name"));
            prodMap.put("description", rs.getString("description"));
            prodMap.put("quantity", rs.getInt("quantity"));
            prodArr.add(prodMap);
        }
        result = prodArr.toString();

        return result;
    }

}

From source file:com.assignment4.productdetails.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)/*  ww w .  j a va 2  s .c o  m*/
public String getproduct(@PathParam("id") int id) throws SQLException {

    if (conn == null) {
        return "it not able to connect";
    } else {
        String query = "Select * from products where product_id = ?";
        PreparedStatement prestmt = conn.prepareStatement(query);
        prestmt.setInt(1, id);
        ResultSet res = prestmt.executeQuery();
        String results = "";
        JSONArray podtAr = new JSONArray();
        while (res.next()) {
            Map pdtmap = new LinkedHashMap();
            pdtmap.put("productID", res.getInt("product_id"));
            pdtmap.put("name", res.getString("name"));
            pdtmap.put("description", res.getString("description"));
            pdtmap.put("quantity", res.getInt("quantity"));
            podtAr.add(pdtmap);
        }
        results = podtAr.toString();

        return results;
    }

}

From source file:com.product.Product.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *//*from w  ww  . ja  va2  s .  c o m*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (connect == null) {
        return "not connected";
    } else {
        String query = "Select * from products";
        PreparedStatement prepstmnt = connect.prepareStatement(query);
        ResultSet rs = prepstmnt.executeQuery();
        String result = "";
        JSONArray productArr = new JSONArray();
        while (rs.next()) {
            Map productMap = new LinkedHashMap();
            productMap.put("productID", rs.getInt("product_id"));
            productMap.put("name", rs.getString("name"));
            productMap.put("description", rs.getString("description"));
            productMap.put("quantity", rs.getInt("quantity"));
            productArr.add(productMap);
        }
        result = productArr.toString();
        return result.replace("},", "},\n");
    }

}