Esempio n. 1
0
  public static List<Personal> listaPersonal() {
    String query = "SELECT * FROM  " + nameTable();
    List<Personal> personas = new ArrayList<Personal>();

    try {
      Connection con = Conexion.createConnection();
      PreparedStatement preparedStatement = con.prepareStatement(query);
      ResultSet p = preparedStatement.executeQuery();
      while (p.next()) {
        Personal personal = new Personal();
        personal.id = p.getInt(nameField()[0]);
        personal.nombre = p.getString(nameField()[1]);
        personal.correo = p.getString(nameField()[2]);
        personal.seguroSocial = p.getString(nameField()[3]);
        personal.telefono = p.getLong(nameField()[4]);
        personal.direccion = p.getString(nameField()[5]);
        personal.lugarnaciemiento = p.getString(nameField()[6]);

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(p.getString(nameField()[7]));
        personal.fechanacimeinto = formatter.parse(p.getString(nameField()[7]));
        personal.puesto_id = p.getInt(nameField()[8]);
        personal.activo = p.getInt(nameField()[9]);
        personas.add(personal);
      }
    } catch (SQLException ex) {
      System.out.println(ex.getMessage());
    } catch (Exception e) {

    }
    return personas;
  }
Esempio n. 2
0
  public Personal persona(int id) {

    String query = "SELECT * FROM  `" + nameTable() + "`  WHERE  " + nameField()[0] + "=?;";
    personal = new Personal();
    try {
      Connection con = Conexion.createConnection();
      PreparedStatement preparedStatement = con.prepareStatement(query);
      preparedStatement.setString(1, id + "");
      ResultSet p = preparedStatement.executeQuery();
      if (p.next()) {
        personal.id = p.getInt(nameField()[0]);
        personal.nombre = p.getString(nameField()[1]);
        personal.correo = p.getString(nameField()[2]);
        personal.seguroSocial = p.getString(nameField()[3]);
        personal.telefono = p.getLong(nameField()[4]);
        personal.direccion = p.getString(nameField()[5]);
        personal.lugarnaciemiento = p.getString(nameField()[6]);
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        personal.fechanacimeinto = formatter.parse(p.getString(nameField()[7]));
        personal.puesto_id = p.getInt(nameField()[8]);
        personal.activo = p.getInt(nameField()[9]);
      }
    } catch (SQLException ex) {
      System.out.println(ex.getMessage());
    } catch (Exception e) {

    }

    return personal;
  }
Esempio n. 3
0
  // validaciones here
  public boolean validate(Personal personal) {
    this.personal = personal;
    boolean value = true;
    if (personal.fechanacimeinto == null) {
      error += "Fecha no puede ser nula \n";
      value = false;
    }
    if (personal.nombre == null) {
      error += "Nombre invalido \n";
      value = false;
    } else {
      if (personal.nombre.trim().isEmpty()
          | personal.nombre.length() > 100
          | personal.nombre.length() < 5) {
        error += "Nombre invalido \n";
        value = false;
      }
    }
    if (personal.correo == null) {
      error += "Correo invalido \n";
      value = false;
    } else {
      if (!validateEmail(personal.correo)) {
        error += "Correo invalido \n";
        value = false;
      }
    }
    if (personal.direccion == null) personal.direccion = "";
    if (personal.lugarnaciemiento == null) personal.lugarnaciemiento = "";

    return value;
  }