Description:
When setQueryTimeout() is called and timeout happens, Connector/J raises MySQLTimeoutException.
But when MAX_STATEMENT_TIME (introduced by MySQL 5.7.4) is set and timeout happens, Connector/J raises SQLException only.
How to repeat:
- MAX_STATEMENT_TIME
java.sql.SQLException: Query execution was interrupted, max_statement_time exceeded
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:2188)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:2044)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3549)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:489)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3240)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2411)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2834)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
at jdbc.Timeout.main(Timeout.java:19)
- setQueryTimeout
com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2966)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
at jdbc.Timeout.main(Timeout.java:22)
Suggested fix:
setQueryTimeout() sets StatementImpl.wasCancelled as true,
so I think MAX_STATEMENT_TIME should do it,
or SQLError#createSQLException should handle this flag.