How do I send a ResultSet back to a client using RMI?

Tim Rohaly

java.sql.ResultSet is not serializable, so it cannot be sent over an RMI connection. You will need to extract the data from the ResultSet and encapsulate it in a serializable object to send back to your client. Or, wrap the ResultSet in a remote object, and make that remote object available to your client.

A danger with the second method is that you are giving control over the life span of the ResultSet to the client--as long as the client holds a reference to the remote object your server must maintain the database connection. Because database connections are vital system resources, you probably want to maintain control of them entirely on the server side or in a middle tier.