My Oracle Support Banner

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 FEBRUARY 19, 2021

Applies to:

JDBC - Version 10.2.0.3 and later
Information in this document applies to any platform.

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 the Oracle database 19.3 with the JDBC driver 19.3 (ojdbc8.jar)

Solution

To view full details, sign in with your My Oracle Support account.

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


In this Document
Goal
Solution
References

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.