Netbeans - LISTAR MEDIANTE UNA BUSQUEDA AYUDAAAAAAAAAAAA!

 
Vista:

LISTAR MEDIANTE UNA BUSQUEDA AYUDAAAAAAAAAAAA!

Publicado por DIANA (1 intervención) el 11/07/2013 04:56:01
Tengo una sola clase llamada celularplan sus atributos son
1
2
3
4
5
6
private int cel_id;
private int cel_num;
private String cel_compania;
private int cel_minPlan;
private int cel_valorPlan;
private String cel_fechaCompra;


hice un JFRAME donde se agrega cada atributo ...tengo el buscar por id y el listar , estoy trabajando por medio de capas , tengo una clase llamada TCELULAR allí hago los métodos para cada operación (ya creada la clase CELULAR con los atributos y métodos correspondientes a la clase) por ejemplo el método para listar que va en TCELULAR es este :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  //metodo de despliegue usando colecciones
    public List<Celular> listarCelulares()
    { List<Celular> lista=new ArrayList<Celular>();
      try {
         orden=conex.abrirConexionBD().createStatement();//Procedimiento abreviado
         resul=orden.executeQuery("SELECT * FROM celularplan");
        while(resul.next())
         { int cel_id=Integer.parseInt(resul.getString(1));
           int cel_num=Integer.parseInt(resul.getString(2));
          String cel_compania=resul.getString(3);
           int cel_minPlan=Integer.parseInt(resul.getString(4));
           int cel_valorPlan=Integer.parseInt(resul.getString(5));
           String cel_fechaCompra=resul.getString(6);
          //Agregar objeto a la lista en forma secuencial
          lista.add(new Celular(cel_id,cel_num,cel_compania,cel_minPlan,cel_valorPlan,cel_fechaCompra));
        }
        } catch (Exception e) { System.out.println("ERROR, NO se pudo generar lista..."); }
     return lista;
    }


Luego el próximo código que va en el botón "listar" en la interfaz gráfica es este:

1
2
3
4
5
6
7
8
9
10
11
12
int fila=0;
        try {
         for (Celular celular : tCelular.listarCelulares())         {tblCelulares.setValueAt(celular.getCel_id(), fila, 0);
            tblCelulares.setValueAt(celular.getCel_num(), fila, 1);
         tblCelulares.setValueAt(celular.getCel_compania(), fila, 2);
            tblCelulares.setValueAt(celular.getCel_minPlan(), fila, 3);
           tblCelulares.setValueAt(celular.getCel_valorPlan(), fila, 4);
           tblCelulares.setValueAt(celular.getCel_fechaCompra(), fila, 5);
            fila++;
           }
          } catch (Exception e) {
        }


Eso sale todo bien ahora ....
LO QUE DEBO HACER AHORA ES : LISTAR TODOS LOS CELULARES QUE TENGAN CIERTO VALOR POR EJEMPLO PONGO UNA BÚSQUEDA POR VALOR Y AL ESCRIBIRLA Y DARLE AL BOTÓN LISTAR ME APAREZCAN TODOS LOS CELULARES QUE TENGAN SOLO ESE VALOR.
COMO HAGO ESO?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder