• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • 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.
 
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.
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • 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.
 
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 ]
 
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.
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic