I need to list an array to show it in a table (specifically the user table with its attributes), I'm using JSTL to show the data in the JSP, the only problem is that it only lists the first object of my ArrayList, here I leave the code of the function that generates the ArrayList.
public List<Usuario_DTO_bean> listarUsuarios() {
List<Usuario_DTO_bean> listaUsuario= new ArrayList<>();
try {
con=Conector.connect();
String sql = "select * from usuario";
Statement statement=con.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while(resultSet.next()) {
int id = resultSet.getInt("id");
String usu = resultSet.getString("usuario");
String clave = resultSet.getString("clave");
String permisos=resultSet.getString("permisos");
int estado=resultSet.getInt("estado");
Usuario_DTO_bean usuario_DTO_bean=new Usuario_DTO_bean(id, usu, clave, permisos, estado);
listaUsuario.add(usuario_DTO_bean);
resultSet.close();
statement.close();
con.close();
System.out.println("nuevo registro");
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
return listaUsuario;
}
When I call to print the first data by console there is no problem, the following is the code that is in a main class that I use to show data by console
Usuario_DTO_bo listar=new Usuario_DTO_bo();
List<Usuario_DTO_bean> lista=new ArrayList<>();
lista=listar.listarUsuarios();
int tamano=lista.size();
String aux=lista.get(0).getUsuario();
System.out.println(aux);
System.out.println(tamano);
Result by console
When I access the position 1 or higher of my array to read the data it sends me the second error (which is because the arrayList only has 1 element I know)