Bug #9906 Connector/J: QueryTimeout is ignored in Statement
Submitted: 14 Apr 2005 14:25 Modified: 11 Nov 2009 2:35
Reporter: Stephan Fudeus Email Updates:
Status: Won't fix Impact on me:
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.7 OS:Linux (linux)
Assigned to:
Triage: D5 (Feature request)

[14 Apr 2005 14:25] Stephan Fudeus
Via com.mysql.jdbc.Statement a query-timeout can be set via setQueryTimeout().
Upon execution of this method, a variable will be set and the same variable can be read via getQueryTimeout(). 
However, this timeout is completely ignored upon further work ...
The variable timeout will never be read.

So any application assuming that the query returns after maximal <timeout> seconds will fail.

How to repeat:
just look at the code ...

Suggested fix:
I would say, either it has to be implemented or a SQLException should be thrown when calling setQueryTimeout().
[14 Apr 2005 14:49] Mark Matthews
We can't implement this until the server does. Unfortunately, unlike other methods (such as .cancel()), the APIDOCs or the JDBC specification don't give a lot of information about what a driver should do if the operation is not supported. If we throw an exception in this case, we'll break a lot of applications that call this method that don't really require the timeout to be respected.
[15 Apr 2005 7:10] Stephan Fudeus
Is this a feature planned for the future?
Could you estimate when it will be implemented?

btw: The exception-handling is inconsistent. 
For normal statements no SQLException is thrown (I understand your reasons). But there is the "UltraDevWorkaround"-class, which defines a callable statement. If you call setQueryTimeout() here, you will get a SQLException("Not Supported")
[1 Jul 2008 6:11] Ken Johanson
Mark, I am curious, can this not be implemented by?:

1) timeouts less than soTimeout:
long start = System.currentTimeMillis();
while (notEOS)
//read data from socket inputstream
if (System.currentTimeMillis()-now>timeout)
  throw new SqlException("timed out");

and also by setting the socket's soTimeout (read-timeout, case where socket is not longer valid)?:

//start query
try {
//read data
} catch (SocketTimeoutException e) {
  throw new SqlException("timed out");
//end query
sock.setSoTimeout(some longer/default value for pools);