Problems with finder that returns collection
Hi. I have make a finder method that looks like this:
public java.util.Collection ejbFindPerEns(short Codi)throws FinderException{
java.util.ArrayList temp=new java.util.ArrayList();
Connection con=null;
PreparedStatement ps=null;
try{
con=getConnection();
ps=con.prepareStatement("select * from taula where codi="+Codi);
ResultSet rs=ps.executeQuery();
if (!rs.next()){
System.out.println("Not element found");
}else{
classEJB elem1=new classEJB();
System.out.println(rs.getShort("codi")+" "+rs.getShort("camp2")+" "+rs.getString("camp3"));
elem1.Codi=rs.getShort("codi");
elem1.Camp2=rs.getShort("camp2");
elem1.Camp3=rs.getString("camp3");
temp.add(elem1);
while (rs.next()){
classEJB elem2=new classEJB();
System.out.println(rs.getShort("codi")+" "+rs.getShort("camp2")+" "+rs.getString("camp3"));
elem2.Codi=rs.getShort("codi");
elem2.Camp2=rs.getShort("camp2");
elem2.Camp3=rs.getString("camp3");
temp.add(elem2);
}
}
rs.close();
}catch (Exception ex){
ex.printStackTrace();
}
return temp;
}
Well, I Think it works, because in the file of logs of IPLANET the fields are printed. But in the code of the client:
java.util.Iterator i=Cerca.iterator();
while (i.hasNext()){
Object o=i.next();
classEJB elem=(classEJB) javax.rmi.PortableRemoteObject.narrow(o, classEJB.class);//This breaks here!!!!!!!!!!!!!!!!!!!!!!
out.println(" "+elem.Codi +" "+elem.Camp2+" "+elem.Camp3);
}
The error that returns is
java.lang.ClassCastException
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.<init>(Compiled Code)
at java.lang.Exception.<init>(Compiled Code)
at java.lang.RuntimeException.<init>(RuntimeException.java:37)
at java.lang.ClassCastException.<init>(ClassCastException.java:36)
at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at prova.testConexio.processRequest(Compiled Code)
at prova.testConexio.doGet(testConexio.java:140)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at com.netscape.server.servlet.servletrunner.ServletInfo.service(Unknown Source)
at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Unknown Source)
at com.kivasoft.applogic.AppLogic.execute(Unknown Source)
at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Native Method)
at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
at java.lang.Thread.run(Compiled Code)

