Пример #1
0
  @Override
  public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {
      CompraDao_Mysql oCompraDAO = new CompraDao_Mysql(Conexion.getConection());
      CompraBean oCompra = new CompraBean();
      Gson gson = new Gson();
      String jason = request.getParameter("json");
      jason = EncodingUtil.decodeURIComponent(jason);
      oCompra = gson.fromJson(jason, oCompra.getClass());
      Map<String, String> data = new HashMap<>();
      if (oCompra != null) {
        oCompra = oCompraDAO.set(oCompra);
        data.put("status", "200");
        data.put("message", Integer.toString(oCompra.getId()));
      } else {
        data.put("status", "error");
        data.put("message", "error");
      }
      String resultado = gson.toJson(data);
      return resultado;
    } catch (Exception e) {
      throw new ServletException("CompraSaveJson: View Error: " + e.getMessage());
    }
  }
Пример #2
0
  @Override
  public ArrayList<String> getColumnsNames() throws Exception {
    ArrayList<String> alColumns = null;
    try {
      oMysql.conexion(enumTipoConexion);
      alColumns = oMysql.getColumnsName("producto", Conexion.getDatabaseName());
      oMysql.desconexion();

    } catch (Exception e) {
      throw new Exception("ProductoDao.removeProducto: Error: " + e.getMessage());
    } finally {
      oMysql.desconexion();
    }
    return alColumns;
  }
Пример #3
0
 @Override
 public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
   String data;
   try {
     if (request.getParameter("id") == null) {
       data = "{\"error\":\"id is mandatory\"}";
     } else {
       ProductoDao oProductoDAO = new ProductoDao(Conexion.getConection());
       ProductoBean oProducto = new ProductoBean();
       oProducto.setId(Integer.parseInt(request.getParameter("id")));
       oProductoDAO.get(oProducto);
       data = new Gson().toJson(oProducto);
     }
     return data;
   } catch (Exception e) {
     throw new ServletException("ProductoGetJson: View Error: " + e.getMessage());
   }
 }