hexiaoquan
asked on
how do client get data packet returned from EJB method (public List getResultset(String sql)) ?
Hi,
where I define one method in Entity bean which return query result,I test it in Entity bean body,it can get right return.But from client ,I can not get returned data. What is the reason for that?
java.lang.NullPointerExcep tion
void com.evermind.server.rmi.RM IConnectio n.EXCEPTIO N_ORIGINAT ES_FROM_TH E_REMOTE_S ERVER(java .lang.Thro wable)
RMIConnection.java:1558
java.lang.Object com.evermind.server.rmi.RM IConnectio n.invokeMe thod(com.e vermind.se rver.rmi.R MIContext, long, long, java.lang.reflect.Method, java.lang.Object[])
RMIConnection.java:1511
java.lang.Object com.evermind.server.rmi.Re moteInvoca tionHandle r.invoke(j ava.lang.O bject, java.lang.reflect.Method, java.lang.Object[])
RemoteInvocationHandler.ja va:55
java.lang.Object com.evermind.server.rmi.Re coverableR emoteInvoc ationHandl er.invoke( java.lang. Object, java.lang.reflect.Method, java.lang.Object[])
RecoverableRemoteInvocatio nHandler.j ava:22
java.util.List __Proxy1.getResultset(java .lang.Stri ng)
void Samplebbs_live.Tb_userClie nt.main(ja va.lang.St ring[])
Tb_userClient.java:84
Entity Bean:
public List getResultset(String sql)
{
List list = new ArrayList();
try
{
dbconn = getConnection();
st = dbconn.createStatement();
rs = st.executeQuery(sql);
ResultSetMetaData mtdata = rs.getMetaData();
if (rs==null)
{
System.out.println("null data");
return Collections.EMPTY_LIST;
}
int col = mtdata.getColumnCount();
while (rs.next())
{
map = new HashMap(col);
for (int i=1;i<=col;i++)
{
map.put(mtdata.getColumnNa me(i),rs.g etString(i ));
}
list.add(map);
}
dbclose(st,rs,dbconn);
for (int j=0;j<list.size();j++)
{
Map m = new HashMap(col);
m = (Map)list.get(j);
System.out.println(j);
System.out.println((String )m.get("ma iladdr"));
}
}
catch (Exception se)
{
se.printStackTrace();
return Collections.EMPTY_LIST;
} System.out.println("4");
return list;
}
but when I called it from client by the following way:
...............
List lt = new ArrayList();
lt = tb_user.getResultset("sele ct * from tb_user"); ---error here
//tb_user ---EJB Object
..............
where I define one method in Entity bean which return query result,I test it in Entity bean body,it can get right return.But from client ,I can not get returned data. What is the reason for that?
java.lang.NullPointerExcep
void com.evermind.server.rmi.RM
RMIConnection.java:1558
java.lang.Object com.evermind.server.rmi.RM
RMIConnection.java:1511
java.lang.Object com.evermind.server.rmi.Re
RemoteInvocationHandler.ja
java.lang.Object com.evermind.server.rmi.Re
RecoverableRemoteInvocatio
java.util.List __Proxy1.getResultset(java
void Samplebbs_live.Tb_userClie
Tb_userClient.java:84
Entity Bean:
public List getResultset(String sql)
{
List list = new ArrayList();
try
{
dbconn = getConnection();
st = dbconn.createStatement();
rs = st.executeQuery(sql);
ResultSetMetaData mtdata = rs.getMetaData();
if (rs==null)
{
System.out.println("null data");
return Collections.EMPTY_LIST;
}
int col = mtdata.getColumnCount();
while (rs.next())
{
map = new HashMap(col);
for (int i=1;i<=col;i++)
{
map.put(mtdata.getColumnNa
}
list.add(map);
}
dbclose(st,rs,dbconn);
for (int j=0;j<list.size();j++)
{
Map m = new HashMap(col);
m = (Map)list.get(j);
System.out.println(j);
System.out.println((String
}
}
catch (Exception se)
{
se.printStackTrace();
return Collections.EMPTY_LIST;
} System.out.println("4");
return list;
}
but when I called it from client by the following way:
...............
List lt = new ArrayList();
lt = tb_user.getResultset("sele
//tb_user ---EJB Object
..............
Can you do a System.out.println(list) in your EJB before this line: return list; and tell us the output?
Also look at the server console/logs for any possible exceptions.
ASKER
Yeah,I can get System.out.println(List) in EJB
for (int j=0;j<list.size();j++)
{
Map m = new HashMap(col);
m = (Map)list.get(j);
System.out.println(j);
System.out.println((String )m.get("ma iladdr"));
}
It can run well.
Now I get the right answer,Return value Type shout implements java.io.Serializable,
but list do not implement it.so I change it to Vector or rowset.It is ok now
thanks.
for (int j=0;j<list.size();j++)
{
Map m = new HashMap(col);
m = (Map)list.get(j);
System.out.println(j);
System.out.println((String
}
It can run well.
Now I get the right answer,Return value Type shout implements java.io.Serializable,
but list do not implement it.so I change it to Vector or rowset.It is ok now
thanks.
Ah... yes true, the object should implement serializable if you want to return it...
Please ask a question here https://www.experts-exchange.com/Community_Support/ for zero points to PAQ the question and refund the points to you.
Please ask a question here https://www.experts-exchange.com/Community_Support/ for zero points to PAQ the question and refund the points to you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.