Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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;
  }