-2

I want to pass a ResultSet from a server to the client and then put all my values in a JTable(it is already in the client). I want to use JSonObject, but I don't understand if I have to serialize it to send it, or I have to directly send it to the client. Is it better to use JSonObject or there is another way?

salvo9415
  • 93
  • 1
  • 14
  • You may want to pass the data within a ResultSet back to the client, but I don't think you want to send the actual ResultSet object, or? Please specify. – ControlAltDel Nov 21 '15 at 21:42

2 Answers2

1

Sending an object over a TCP connection is possible (and fairly easy). However, said object must be an instance of a class which implements Serializable. ResultSet is an interface and does not extend Serializable.

If ResultSet extended Serializable (and the reasoning as to why it doesn't is shown in the second link), then it could be sent via an ObjectOutputStream. If it was a class as opposed to an interface, it could be extended (assuming it is not a final class and it has at least one non-private constructor) and the extension could then implement Serializable. Again, this is not the case.

As a result, you must instead read the values from the ResultSet on the server and then send them as opposed to sending the ResultSet itself.

Community
  • 1
  • 1
Alexander Guyer
  • 2,063
  • 1
  • 14
  • 20
0

You should never return a ResultSet to a client, the clients should not know what kind of processing is done on the server (this case we can know some kind of DB operation is done, the point of abstraction is lost). Better approach would be to convert the ResultSet into a collection and return the collection(such as ArrayList) to client.

Akash Babu
  • 227
  • 1
  • 4
  • 13