I copy thread:http://groups.google.com/group/comp.lang.java.programmer/
browse_thread/thread/ce769dddbb2700af?hl=en#
================================
mttc wrote:
> I try it with MSSQL 2005. and it's seem the is not work!
> swtQueryTimeout is Apply only on lock?
...
> the query not ended forever!
If you talk about [1], it claims to be a JDBC 4.0 compliant driver.
The API of java.sql.Statement cleary states that if "the limit is
exceeded, an SQLException is thrown.". This somewhat contradicts the
statement that is given by the JDBC 4.0 Final Release specification
in
13.1.3 ("Limiting the execution time for Statement Objects"):
"A JDBC driver must apply this limit to the execute, executeBatch,
executeQuery and executeUpdate methods. Once the data source has had
an
opportunity to process the request to terminate the running command,
a
SQLException will be thrown to the client [...]"
Obviously, the specification makes an additional requirement for the
SQLException to be thrown, namely the data source must have had an
opportunity to process the request to terminate the running command
(I
filed a bug report due to incomplete API docs).
My interpretation of this is, that it is not guaranteed that a
SQLException will be thrown if the limit is exceeded. But if a
SQLException is thrown, you can be sure that the running command has
been terminated already.
Yet, I think you should report a bug to MS.
Bye
Michael
[1] Microsoft SQL Server JDBC Driver 2.0 Community Technology Preview
(January 2009) -
<http://www.microsoft.com/downloads/details.aspx?
FamilyID=f914793a-6fb...>
========================================
So what we do?
I sure that timeout with .NET stop waiting for unplug cable, even
socket not report error. I not think that have app that prefer
behaviour of waiting eternity.
I agree with you, in that the driver could/should have a (one) utility
thread that handles all timeouts for any connections, connection
attempts, statements etc. (never have one thread per connection),
but the question is what the driver can do to make the connection
viable after the timeout. Until the DBMS does respond to the original
query or the cancel, the connection is useless...
C:\Java>java TimeoutTest
Driver version is 2.0.1008.2
DBMS version is 9.00.3310
com.microsoft.sqlserver.jdbc.SQLServerException: The query has timed out.
at
com.microsoft.sqlserver.jdbc.SQLServerException.makeInterruptException(SQLSe
rverException.java:171)
at
com.microsoft.sqlserver.jdbc.TDSCommand.interrupt(IOBuffer.java:4238)
at com.microsoft.sqlserver.jdbc.TimeoutTimer.run(IOBuffer.java:3885)
at java.lang.Thread.run(Unknown Source)
My Code:
PreparedStatement ps = cn.prepareCall("EXEC ap_TightLoop");
ps.setQueryTimeout(10);
ps.executeQuery();