Esempio n. 1
0
  public JSONArray ObtenerMateriales() {
    JSONArray Materiales = new JSONArray();
    JSONObject material = new JSONObject();

    try {
      this.cn = getConnection();
      this.st = this.cn.createStatement();
      String sql;
      sql = "SELECT * FROM material";
      this.rs = this.st.executeQuery(sql);

      while (this.rs.next()) {
        Material mat = new Material(rs.getString("codigo"), rs.getString("material"));
        material = mat.getJSONObject();
        System.out.printf(material.toString());
        Materiales.add(material);
      }

      this.desconectar();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return (Materiales);
  }
Esempio n. 2
0
 public JSONObject DatosMaterial(String Codigo) {
   JSONObject mater = new JSONObject();
   try {
     this.cn = getConnection();
     this.st = this.cn.createStatement();
     String sql = "SELECT * FROM material WHERE codigo = '" + Codigo + "';";
     this.rs = this.st.executeQuery(sql);
     this.rs.first();
     Material use = new Material(rs.getString("codigo"), rs.getString("material"));
     mater = use.getJSONObject();
     this.desconectar();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return (mater);
 }
Esempio n. 3
0
  public boolean AdicionarMaterial(JSONObject datos) {
    try {
      this.cn = getConnection();
      this.st = cn.createStatement();
      Material use = new Material("", String.valueOf(datos.get("material")));
      String tsql;
      tsql = "INSERT INTO material VALUES(DEFAULT, '";
      tsql += use.getNombre_material() + "')";
      this.st.execute(tsql);
      this.desconectar();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }
Esempio n. 4
0
  public boolean ModificarMaterial(JSONObject datos, String Codigo) {
    try {
      this.cn = getConnection();
      this.st = cn.createStatement();
      Material use = new Material("", String.valueOf(datos.get("material")));
      String tsql;
      tsql =
          "UPDATE material SET material='"
              + use.getNombre_material()
              + "' WHERE codigo = "
              + Codigo
              + ";";
      this.st.execute(tsql);
      this.desconectar();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }