Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
s shan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic