How to use the JDBC setQueryTimeout Call to Cancel a Long Running Query and raise an ORA-1013 (Doc ID 412171.1)

Last updated on OCTOBER 06, 2017

Applies to:

JDBC - Version 10.2.0.3 to 12.1.0.2.0 [Release 10.2 to 12.1]
Information in this document applies to any platform.
***Checked for relevance on 29-Feb-2016***

Goal

This article provides a very simple JDBC standalone program to demonstrate the use of the JDBC standard method setQueryTimeout() which is available for all JDBC java.sql.Statement objects.  The article will also discuss limitations that may prevent the setQueryTimeout() from working properly due to limitations of both the database and the JDBC driver.

The Statement.setQueryTimeout(int seconds) relies on the Statement.cancel() method and basically implements a thread to cancel a long running query after a specified delay.

This demonstration builds on  <Note 357615.1> How to simulate a slow query. Useful for testing of timeout issues

 This program has been tested using RDBMS 10.2.0.3 ( Linux x86 32-bit) JDBC/thin 10.2.0.3, JDBC/thin 11.1.0.6, JDBC/thin 11.2.0.2 and JDK 1.5 / 1.6 ( Windows client)

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms