It's not a secret anymore!*
The moose likes Distributed Java and the fly likes how can return a ResultSet object from a server to client? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how can return a ResultSet object from a server to client?" Watch "how can return a ResultSet object from a server to client?" New topic

how can return a ResultSet object from a server to client?

s shan

Joined: Jul 30, 2003
Posts: 9
Hi i tried to return a resultset object from a server to client in RMI, i got an unmarshalling exception. Can anyone help me to handle it. Or what is the other alternative?

preparing for scjp6.0
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Please check your private messages.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

You can only return Serializable objects from remote method invocation.
Since, ResultSet is not Serializable, you will get an Unmarshalling exception.

You must read the results from the ResultSet, create a Java serializable object and return this object.

apigee, a better way to API!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
ResultSet is an interface. It doesn't extend Serializable, so one cannot guarantee that all ResultSets will be Serializable. In theory, some implementations of ResultSet might be Serializable, although probably not, as it doesn't sound like a good idea to me.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Pat Farrell

Joined: Aug 11, 2007
Posts: 4646

I'm surprised no one has replied with my first answer to the question:

That's a bad idea, what are you really trying to do?

In 99% of the cases, you want to see either the whole result set, or some aggregated function (ave(cost)) over the rows. So send either the array or the answer, don't make the calling code handle all the cruft of a ResultSet.
Navin D Waghmare

Joined: May 13, 2008
Posts: 1
ResultSet is not Serializable, so an alternative is fill the data in some Serializable object, which could be a Vector.
Vector is the serializable.

Yesterday, I have done the same to get the result set data.

Use Vector and then return the Vector to client from the Server.

Hope this will help you.
[ May 13, 2008: Message edited by: Navin D Waghmare ]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
May I suggest the use of ArrayList or any other class from the new Collections Framework, instead of the legacy Vector class?

Also, you must take into account that, although the Java collections are serializable, the contents of a collection may not be.

Make sure the objects you put into the collection are serializable, otherwise you will get an error.
I agree. Here's the link:
subject: how can return a ResultSet object from a server to client?
Similar Threads
Handling huge resultset
passing resulset object to client in rmi
Serialzation is not working
RMI client/server JVM