Guest User

Untitled

a guest
Aug 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. /* it's here the source of the ArrayList functions when i'm to build the query in mysql */
  2.  
  3. public ArrayList listar(ConexionSicodet conn, String valor) throws SQLException{
  4.         ArrayList arreglo= new ArrayList();
  5.         stm = conn.stm;
  6.         res = stm.executeQuery("select iddelito as id, upper(descripcion) as descripcion, estatus as estatus from delito where descripcion like '%"+valor.toUpperCase()+"%' ");
  7.         ResultSetMetaData rsmd = res.getMetaData();
  8.         int columnas = rsmd.getColumnCount();
  9.         while(res.next()){
  10.             HashMap fila = new HashMap();
  11.             arreglo.add(fila);
  12.             for(int i = 0; i < columnas; i++){
  13.                 fila.put(rsmd.getColumnName(i+1), res.getObject(i+1));
  14.                 //System.out.println(arreglo.get(i));
  15.                 //System.out.println("Registro: "+rsmd.getColumnName(i+1)+"\nobjeto: "+res.getObject(i+1));
  16.             }
  17.         }
  18.         return arreglo;
  19.     }
  20.  
  21. public static void main(String []args){
  22.     ConexionSicodet conn = new ConexionSicodet();
  23.     ModeloDelito md = new ModeloDelito();
  24.     ArrayList arreglo = md.listar(conn, "valor");
  25.     int tamano = arreglo.size();
  26.     if(tamano>0){
  27.         for(int i = 0; i<tamano; i++){
  28.             System.out.println(arreglo.get(i));
  29.         }
  30.     }else{
  31.         System.out.println("arreglo vacio!");
  32.     }  
  33. }
  34.  
  35. /* the problems is thats i can not to select the field of the object of the ArrayList */
Add Comment
Please, Sign In to add comment