private void jTbdescripcionKeyPressed(
      java.awt.event.KeyEvent evt) { // GEN-FIRST:event_jTbdescripcionKeyPressed

    try {
      // se comienza la conexion con la base de datos
      try {
        con = new Conexion();

      } catch (ClassNotFoundException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (SQLException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      }

      String nom = jTbdescripcion.getText();
      String sql = "SELECT * FROM productos WHERE nombre_producto LIKE '" + nom + "%'";
      rs = con.Consulta(sql);

      if (rs == null)
        JOptionPane.showMessageDialog(
            null, "No se encontro: " + jTbdescripcion.getText() + " en la base de datos.");

      // Para establecer el modelo al JTable

      DefaultTableModel buscar =
          new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int rowIndex, int vColIndex) {
              return false;
            }
          };
      this.jTbuscar.setModel(buscar);

      // 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 colimnas
      for (int i = 1; i <= cantidadColumnas; i++) {
        buscar.addColumn(rsMd.getColumnLabel(i));
      }

      while (rs.next()) {
        Object[] fila = new Object[cantidadColumnas];

        for (int i = 0; i < cantidadColumnas; i++) {

          fila[i] = rs.getObject(i + 1);
        }
        buscar.addRow(fila);
      }

    } catch (SQLException ex) {
      Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_jTbdescripcionKeyPressed
  private void jBmodificar1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBmodificar1ActionPerformed
    // BOTON PARA MODIFICAR LOS DATOS DE UN PRODUCTO EN LA BASE DE DATOS

    // validaciones para saber que no se deja algun campo en limpio
    if (jTproducto.getText().equals("")
        || jTbcaducidad.getText().equals("")
        || jTbprecio.getText().equals("")
        || jTbexistencia.getText().equals("")
        || jTbdescripcion2.getText().equals("")
        || jTbespecificaciones.getText().equals("")) {

      JOptionPane.showMessageDialog(null, "Faltan Datos: No Puede Dejar Cuadros en Blanco");

    } else {
      // por si se da clic antes de hacer la busqueda
      // se validan los textfield

      String producto = jTproducto.getText();
      String precio = jTbprecio.getText();
      String caducidad = jTbcaducidad.getText();
      String existe = jTbexistencia.getText();
      String descri = jTbdescripcion2.getText();
      String especi = jTbespecificaciones.getText();

      try {
        // se crea la conexion y las consultas
        con = new Conexion();

        int id2 = Integer.parseInt(id);
        // se crea la sentecia sql y se ejecuta para hacer la modificacion
        String modifica =
            "UPDATE `productos` SET `nombre_producto`='"
                + producto
                + "',`precio`='"
                + precio
                + "',`caducidad`='"
                + caducidad
                + "',`existencia`='"
                + existe
                + "',`descripcion`='"
                + descri
                + "',`especificaciones`='"
                + especi
                + "' WHERE id_producto = '"
                + id2
                + "'";
        con.ejecutar(modifica);
        JOptionPane.showMessageDialog(null, "Datos Actualizados");

      } catch (ClassNotFoundException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      } catch (SQLException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  } // GEN-LAST:event_jBmodificar1ActionPerformed
  private void jBagregarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBagregarActionPerformed

    // BOTON PARA AGREGAR UN PRODUCTO A LA BASE DE DATOS

    int aux = 0;

    // validaciones para saber que no se deja algun campo en limpio
    if (jTnombre.getText().equals("")
        || jTyyyy.getText().equals("")
        || jTprecio.getText().equals("")
        || jTexistencia.getText().equals("")
        || jTdescripcion.getText().equals("")
        || jTespecificaciones.getText().equals("")) {

      JOptionPane.showMessageDialog(null, "Faltan Datos: No Puede Dejar Cuadros en Blanco");

    } else {
      try {
        // se comienza la conexion con la base de datos
        try {
          con = new Conexion();

        } catch (ClassNotFoundException ex) {
          Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
          Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
          Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
          Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
        // se obtienen los valores de los jTextField
        String nombre = jTnombre.getText();
        String caducidad = jTyyyy.getText() + "-" + jTmm.getText() + "-" + jTdd.getText();
        String existencia = jTexistencia.getText();
        String precio = jTprecio.getText();
        String descripcion = jTdescripcion.getText();
        String especifica = jTespecificaciones.getText();

        // sentencias sql para insertar los datos en la base de datos
        String sql =
            "INSERT INTO `productos`(`nombre_producto`, `precio`, `caducidad`, `existencia`, `descripcion`, `especificaciones`) VALUES ('"
                + nombre
                + "','"
                + precio
                + "','"
                + caducidad
                + "','"
                + existencia
                + "','"
                + descripcion
                + "','"
                + especifica
                + "')";

        // funcion para ejecutar la query
        con.ejecutar(sql);

        JOptionPane.showMessageDialog(null, "Producto: " + nombre + " agregado.");

        jTnombre.setText("");
        jTprecio.setText("");
        jTyyyy.setText("");
        jTmm.setText("");
        jTdd.setText("");
        jTexistencia.setText("");
        jTdescripcion.setText("");
        jTespecificaciones.setText("");

      } catch (SQLException ex) {
        Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  } // GEN-LAST:event_jBagregarActionPerformed