/** Creates new form PrincipalCliente */
  public ModificarAdmin() {
    initComponents();
    conexioninicio ci = new conexioninicio();
    ci.conectar();
    this.setSize(470, 650);
    this.setLocationRelativeTo(null); // Centra la ventana Splash
    try {
      Connection con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      //  System.out.println("Conexion a la base de datos cliente realizada con exito! ");
      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT * FROM tienda.estado ;");
      // obteniendo la informacion de las columnas que estan siendo consultadas
      ResultSetMetaData rsMd = rs.getMetaData();
      // La cantidad de columnas que tiene la consulta
      int cantidadColumnas = rsMd.getColumnCount();
      // Establecer como cabezeras el nombre de las columnas

      // Creando las filas para el Jtable
      while (rs.next()) {
        Object[] fila = new Object[cantidadColumnas];
        for (int i = 1; i < cantidadColumnas; i++) {
          jComboBox1.addItem(rs.getObject(i + 1));
        }
      }
      rs.close();
      con.close();

    } catch (Exception e) {

      JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    conexioninicio ci = new conexioninicio();
    Connection con = null;

    try {
      Class.forName("org.gjt.mm.mysql.Driver");
      con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      Statement stmt = con.createStatement();
      String cadenasql =
          "select nombre,apPat,apMat,calle,numExt,colonia,municipio,cp,email,numTel,curp,idadmon,contraseña,nombreest from persona natural join admin natural join estado where idadmon="
              + "'"
              + User
              + "'";
      ResultSet rs = stmt.executeQuery(cadenasql);
      while (rs.next()) {
        nombre.setText(rs.getString("nombre"));
        apPat.setText(rs.getString("apPat"));
        apMat.setText(rs.getString("apMat"));
        calle.setText(rs.getString("calle"));
        num.setText(rs.getString("numExt"));
        colonia.setText(rs.getString("colonia"));
        municipio.setText(rs.getString("municipio"));
        cp.setText(rs.getString("cp"));
        email.setText(rs.getString("email"));
        telefono.setText(rs.getString("numTel"));
        curp.setText(rs.getString("curp"));
        idamin.setText(rs.getString("idadmon"));
        contraseñaactual.setText(rs.getString("contraseña"));
        this.jComboBox1.setSelectedItem(rs.getString("nombreest"));
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } // TODO add your handling code here:
  } // GEN-LAST:event_jButton1ActionPerformed
Example #3
0
  /** @param args */
  public static void main(String[] args) {
    try {
      // dyn init of array of emps
      Emp[] e = {
        new Emp(101, "abc", 2400, "23-12-2013"),
        new Emp(23, "abc1", 20000, "1-1-2013"),
        new Emp(56, "def", 40000, "20-3-2013")
      };
      // Create empty ArrayList of emps
      ArrayList<Emp> emps = new ArrayList<>();
      // populate AL using array data
      for (Emp e1 : e)
        // e1=e[0]....
        emps.add(e1);

      // display list contents
      System.out.println("emps via " + emps);
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter emp id & inc  to update");
      Emp e1 = new Emp(sc.nextInt());
      int index = emps.indexOf(e1);
      if (index == -1)
        throw new EmpNotFoundException(
            "Emp with ID " + e1.getId() + " Not found: Updation failed ");
      double inc = sc.nextDouble();
      Emp e2 = emps.get(index);
      e2.setSal(e2.getSal() + inc);
      System.out.println("Updated List " + emps);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
  private void jButton3ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed
    conexioninicio ci = new conexioninicio();
    Connection con = null;
    Connection con1 = null;

    try {
      Class.forName("org.gjt.mm.mysql.Driver");
      con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      con1 = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      Statement stmt = con.createStatement();
      Statement stmts = con1.createStatement();
      String cadenasql =
          "UPDATE persona  SET nombre="
              + "'"
              + nombre.getText().toUpperCase()
              + "'"
              + ","
              + "apPat="
              + "'"
              + apPat.getText().toUpperCase()
              + "'"
              + ","
              + "apMat="
              + "'"
              + apMat.getText().toUpperCase()
              + "'"
              + ","
              + "calle="
              + "'"
              + calle.getText().toUpperCase()
              + "'"
              + ","
              + "colonia="
              + "'"
              + colonia.getText().toUpperCase()
              + "'"
              + ","
              + "numExt="
              + num.getText()
              + ","
              + "municipio="
              + "'"
              + municipio.getText().toUpperCase()
              + "'"
              + ","
              + "numTel="
              + "'"
              + telefono.getText()
              + "'"
              + ","
              + "cp="
              + "'"
              + cp.getText()
              + "',"
              + "curp="
              + "'"
              + curp.getText().toUpperCase()
              + "',"
              + "idestado="
              + "'"
              + jComboBox1.getSelectedIndex()
              + "',"
              + "email="
              + "'"
              + email.getText()
              + "' where curp = '"
              + curp.getText()
              + "'";

      String cadenasql2 =
          "UPDATE admin  SET idadmon="
              + "'"
              + idamin.getText()
              + "',curp="
              + "'"
              + curp.getText().toUpperCase()
              + "' where curp = '"
              + curp.getText()
              + "'";

      stmt.executeUpdate(cadenasql);
      stmts.executeUpdate(cadenasql2);
      //   System.out.print("Se han borrado todos los datos");

      JOptionPane.showMessageDialog(this, "ActualizaCION Exitosa");
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } // TODO add your handling code here:
  } // GEN-LAST:event_jButton3ActionPerformed