I have a method in the model that creates an ArrayList array me from a resultset, I need is cross it from jsp, I could not do, any help?
This is the code of the arraylist
public ArrayList listar(){
String sql="select * from eventos";
ArrayList lista=new ArrayList();
try {
st=con.createStatement();
rs=st.executeQuery(sql);
int NumColumnas=getRows(rs);
while(rs.next()){
String Fila[]=new String [NumColumnas];
for(int x=0;x<NumColumnas;x++){
Fila[x]=rs.getObject(x+1).toString();
}
lista.add(Fila);
}
} catch (SQLException ex) {
Logger.getLogger(EventosBean.class.getName()).log(Level.SEVERE, null, ex);
}
return lista;
}
From the jsp I have this code and I returned values in this format [Ljava.lang.String;@39dc94a4 [Ljava.lang.String;@5d013b69
EventosBean ev=new EventosBean();
ArrayList<EventosBean>arrayList=ev.listar();
out.println(arrayList.size());
Iterator<EventosBean> iterator = arrayList.iterator();
while (iterator.hasNext()) {
out.println(iterator.next());
}
Something is wrong. In your
listar
method, you are returning aArrayList
. ThisArrayList
contains obejcts of typeString[]
. You are capturing this output in aArrayList<EventosBean>
, which expects objects of typeEventosBean
.If you are looking to print content of the
String[]
added inlistar
returnedArrayList
on JSP, make few changes in your code as shown below.and in your class where you are calling
listar