milardovich

Catalogo fixed

Dec 8th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. public ArrayList<Libro> getAll()
  2.     {
  3.         ArrayList<Libro> libros = new ArrayList<Libro>();
  4.         ConeccionDB con = new ConeccionDB();
  5.         Statement st = null;
  6.         ResultSet rs = null;
  7.         String queryString = "SELECT * FROM libros ORDER BY titulo;";
  8.         try
  9.         {
  10.             st = con.getConnection().createStatement();
  11.             rs = st.executeQuery(queryString);
  12.             while(rs.next())
  13.             {
  14.                 Libro libro = new Libro();
  15.                
  16.                 libro.setID(rs.getInt("id_libro"));
  17.                 libro.setTitulo(rs.getString("titulo"));
  18.                 libro.setAutor(rs.getString("autor"));
  19.                 libros.add(libro);
  20.             }
  21.         }
  22.         catch (SQLException e)
  23.         {
  24.             e.printStackTrace();
  25.         }
  26.         finally
  27.         {
  28.             try
  29.             {
  30.                 con.getConnection().close();
  31.                 rs.close();
  32.                 st.close();
  33.             }
  34.             catch (SQLException e)
  35.             {
  36.                 e.printStackTrace();
  37.             }
  38.         }
  39.         return libros;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment