I was getting an odd exception thrown from some EJBs that came, in my code, originally from PreparedStatement.executeQuery().
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The queries were unusual in that the result set would contain a relatively large number of rows. This is not a good practice of course, but I only have a handful of these cases, for good reasons.
One would expect the driver to use a server side cursor. It doesn't. So the solution was to tell the MySQL driver that the results would be scanned forward only, etc. so as to conserve memory.
stmt = conn.prepareStatement("select * from MyLargeTable",
ResultSet rs = stmt.executeQuery();