Troubleshoot an error with the error message "Could not read resultset: unexpected end of stream, read 0 bytes from 4".
The error occurs during communication with the server.
In most cases, this is caused by queries with large result sets. A server usually expects the client to rapidly read the result set. net_write_timeout specifies the read timeout period. The default value is 60s. If the client fails to read the entire result set during this period, the server discards the connection. If you do not want to process the results in the specified period, you can run SET STATEMENT net_write_timeout = 10000 FOR XXX, where XXX indicates a "general" query. In this case, net_write_timeout is set to a larger value, which is 10000 in this example, for this query.
If the application uses many long queries in the fetch size, you can use the sessionVariables = net_write_timeout = xxx option to set the connection.
Perform lightweight ping/ operations to avoid mass "select 1"
You can use Connection.isValid() to perform lightweight ping/ operations to avoid mass "select 1". Connection.isValid() implements ping operations in MySQL, rather than on the network.