-2

I know that ResultSet cannot be serializable due to the connection details present in it. How a database server is able to send a ResultSet which has a connection in it? Can anyone explain this process? I am not able to understand this concept properly. I searched on the internet, and I could not find the relevant details.

Curious
  • 35
  • 1
  • 8
  • 1
    The ResultSet holds a connection to the DBMS server and requests the data as it's needed, the data is not present in the ResultSet right away. The driver does the individual requests and the data handling. – f1sh Feb 07 '19 at 15:21
  • In my project, I have to store ResultSet in the Redis cache. But ResultSet cannot be serializable. While doing this I got a doubt that, how the server is able to send the ResultSet in the socket. – Curious Feb 07 '19 at 15:21
  • 1
    You cannot store the ResultSet. You can however extract all the data you need from the ResultSet in a custom data structure and store that in redis. – f1sh Feb 07 '19 at 15:26
  • @hovercraft-full-of-eels Kindly ready my question properly before marking it as a duplicate. I asked this question about how a server sends a resultset to a client. I did not ask why resultset is not serializable. Kindly comment why you have marked this question as a duplicate. – Curious Feb 07 '19 at 15:26
  • @f1sh I did that I am storing in ArrayList to be specific – Curious Feb 07 '19 at 15:30
  • 1
    conceptually it does seem to me like the duplicate target answers your question. both seem to share a misconception that the resultset is a container for data. what are the existing answers missing? – Nathan Hughes Feb 07 '19 at 15:30
  • @NathanHughes I want to know what happens in the server side when a query which can return a ResultSet is executed. Example: statement.execute() returns a ResultSet. How it is done? – Curious Feb 07 '19 at 15:33
  • 1
    @Curious: as mentioned several times, the ResultSet is **not** sent. Please read or re-read the answer in the duplicate. – Hovercraft Full Of Eels Feb 07 '19 at 16:07
  • The server performs the query and sends the results back over the network as a stream. The jdbc driver collects the bytes coming in and provides them to the code reading from the resultset. Which is basically what Joachim said. Don’t know what more there is to say. – Nathan Hughes Feb 08 '19 at 02:06
  • @NathanHughes Not all databases send a stream of results back in response to the execute. Some databases require the driver to ask for (batches of) rows. – Mark Rotteveel Feb 08 '19 at 07:28

1 Answers1

5

The database doesn't send a ResultSet. The JDBC driver uses some protocol (usually a product-specific one) to communicate to the database. Most often this is over TCP/IP so it boils down to binary data stream (not unlike traditional files).

The data transferred therein is then represented internally in some way that is specific to the JDBC driver implementation, but which can be accessed using a ResultSet implementation.

In other words: the ResultSet is not itself the data that's transferred. It's just a convenient interface that the JDBC driver provides to the user to access the data that is being received from the database.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614