Esempio n. 1
0
  /**
   * Encuentra todas las estaciones principales existentes en la base de datos (activas)
   *
   * @return Lista que contiene objetos EstacionPrincipal, cada uno representa alguna encontrada ,
   *     si no existen estaciones el vector será vacio.
   * @author Leoanrdo Ríos
   */
  public List<EstacionPrincipal> findAllEstacionPrincipal() {
    String sqlConsulta =
        "SELECT id,nombre,ubicacion,estado,id_operario FROM estacion_principal JOIN "
            + " estacion ON estacion_principal.id_estacion = estacion.id WHERE estado=true";

    List<EstacionPrincipal> estaciones = new ArrayList<EstacionPrincipal>();

    try {

      Connection conn = fachada.conectar();
      Statement sentence = conn.createStatement();
      ResultSet table = sentence.executeQuery(sqlConsulta);

      while (table.next()) {
        EstacionPrincipal estacion = new EstacionPrincipal();
        estacion.setEstado(table.getBoolean("estado"));
        estacion.setId(table.getInt("id"));
        estacion.setIdOperario(table.getString("id_operario"));
        estacion.setNombre(table.getString("nombre"));
        estacion.setUbicacion(table.getString("ubicacion"));

        estaciones.add(estacion);
      }
      fachada.cerrarConexion(conn);
    } catch (SQLException se) {
      se.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return estaciones;
  }
Esempio n. 2
0
  public EstacionPrincipal findEstacionPrincipal(String nombre) {
    String sql_query =
        "SELECT id, ubicacion, estado, nombre, id_operario FROM "
            + " estacion_principal JOIN estacion ON estacion_principal.id_estacion="
            + " estacion.id WHERE nombre = '"
            + nombre
            + "'";

    EstacionPrincipal estacion = new EstacionPrincipal();

    try {
      Connection conn = fachada.conectar();
      Statement sequence = conn.createStatement();
      ResultSet table = sequence.executeQuery(sql_query);

      while (table.next()) {
        estacion.setId(table.getInt("id"));
        estacion.setUbicacion(table.getString("ubicacion"));
        estacion.setEstado(table.getBoolean("estado"));
        estacion.setNombre(table.getString("nombre"));
        estacion.setIdOperario(table.getString("id_operario"));
      }

    } catch (SQLException se) {
      se.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return estacion;
  }
Esempio n. 3
0
  public List<EstacionPrincipal> findEstacionesPrincipales(String nombre, String ubicacion) {
    String sql_nombre = "";
    String sql_ubicacion = "";
    String sql_where = "";
    String sql_and = "";
    if (!nombre.equals("") || !ubicacion.equals("")) {
      sql_where = " WHERE ";
    }
    if (!nombre.equals("")) {
      sql_nombre = " nombre like '%" + nombre + "%' ";
      if (!ubicacion.equals("")) sql_and = " and ";
    }
    if (!ubicacion.equals("")) {
      sql_ubicacion = " ubicacion like '%" + ubicacion + "%' ";
    }

    String sql_query =
        "SELECT id, ubicacion, estado, nombre, id_operario FROM "
            + " estacion_principal JOIN estacion ON estacion_principal.id_estacion="
            + " estacion.id "
            + sql_where
            + sql_nombre
            + sql_and
            + sql_ubicacion;

    List<EstacionPrincipal> estaciones = new ArrayList<EstacionPrincipal>();

    try {
      Connection conn = fachada.conectar();
      Statement sequence = conn.createStatement();
      System.err.println(sql_query);
      ResultSet table = sequence.executeQuery(sql_query);

      while (table.next()) {
        EstacionPrincipal estacion = new EstacionPrincipal();
        estacion.setId(table.getInt("id"));
        estacion.setUbicacion(table.getString("ubicacion"));
        estacion.setEstado(table.getBoolean("estado"));
        estacion.setNombre(table.getString("nombre"));
        estacion.setIdOperario(table.getString("id_operario"));
        estaciones.add(estacion);
      }

    } catch (SQLException se) {
      se.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return estaciones;
  }