It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes Returning ResultSet from Bean class to client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Returning ResultSet from Bean class to client" Watch "Returning ResultSet from Bean class to client" New topic
Author

Returning ResultSet from Bean class to client

Gurpreet Sachdeva
Ranch Hand

Joined: Feb 20, 2001
Posts: 90
Hello All,
I am new to EJB world. I need some help.I was just making a simple EJB program. I was trying to get the data from the database and display it at the client side. For this I want to return the ResultSet from Bean class to client.The client is simple java class(Console Based).
I know that to return an object from the Bean class to client the object's class must implement Serializable, which the ResultSet is is not implementing. But I am trying it in some diferrent way. I am adding the ResultSet object to a Vector and returning the Vector. But this is also not working. It is giving me following Exception:
java.rmi.RemoteException: ; nested exception is:
weblogic.rmi.ServerException: A remote exception occurred while executin
g the method on the remote object
- with nested exception:
[weblogic.rmi.MarshalException: error marshalling return
- with nested exception:
[java.io.IOException: Class sun.jdbc.odbc.JdbcOdbcResultSet with code=123 does n
ot implement Serializable, Externalizable or WLSerializable]]
How can I solve this problem?
Please help me?
Thanks
Gurpreet Sachdeva

Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>
Shiv Sidhaarth
Ranch Hand

Joined: Aug 06, 2001
Posts: 119
Hi,
Even if u add resultset into vector, u cant serialize it. You need to create your own class and put all data from resultset to (eg. vector of vector) that class and then serialize it.
Sankar
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Sankar is right on target. For an object to be serialized, all of its component parts must be serializable as well. The solution you must take is to take the data out of the result set and place it in a Serializable object.
I have described an architecture for doing things like that here:
http://www7.software.ibm.com/vad.nsf/Data/Document4359?OpenDocument&p=1&BCT=1&Footer=1
and here:
http://www7b.boulder.ibm.com/wsdd/library/techarticles/0106_brown/sessionfacades.html
In these articles I was using entity beans as a datasource, but using JDBC works in the same way.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Gurpreet Sachdeva
Ranch Hand

Joined: Feb 20, 2001
Posts: 90
Hello Sankar and Brown,
Thanks for your reply.
One thing more, the same thing is working fine when I use JSP as client.I mean I am adding ResultSet to the Vector and returning Vector to the client, and this is working fine in case of JSP as client.
Why is it so?
Regards
Gurpreet Sachdeva
Shiv Sidhaarth
Ranch Hand

Joined: Aug 06, 2001
Posts: 119
Hi,
I have not worked in JSP. But i think, that jsp will be internally converted to servlets. Servlets can run only inside servlet engine environment. So, the data inside resultset is processed inside server and output (eg. html) is sent to client. Hence, i feel resultset is not sent to client directly bcos of which it is working. Hope i am correct.
Sankar
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Put differently, you're not getting the exception from the JSP because your servlet container and your EJB container happen to live inside the same JVM, and the application server never bothers to serialize your result. That's not the kind of behaviour you should rely upon!
Kyle's architecture is definitely the better way to do it (his book has truly excellent coverage of EJB application architecture, by the way). But if you want something quick and dirty, then you could simply return a javax.sql.CachedRowSet (which lives in the JDBC optional package). It's like a ResultSet but without "live" database connection.
- Peter
Gurpreet Sachdeva
Ranch Hand

Joined: Feb 20, 2001
Posts: 90
Thanks all!
Regards
Gurpreet Sachdeva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Returning ResultSet from Bean class to client