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); }
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); }