Skip to Main Content
  • Questions
  • Different JDBC Query Timeout behaviour in Thin and OCI Driver

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Joern.

Asked: August 14, 2019 - 12:00 pm UTC

Last updated: August 19, 2019 - 6:41 pm UTC

Version: 18.3

Viewed 10K+ times! This question is

You Asked

Hi Tom,

In the https://asktom.oracle.com/pls/apex/asktom.search?tag=jdbc-thin-dirver-vs-oci-driver question you stated that one should only use the OCI driver if some OCI-specific features are required.

However, as stated in https://www.thatjeffsmith.com/archive/2013/04/die-or-how-to-cancel-queries-in-oracle-sql-developer/ there is also a huge difference between the Thin and OCI Driver when it comes to the Query Timeout handling.

When I use a Query-Timeout on a select statement that requires a full table scan on a huge table like this
        try (Connection con = dataSource.getConnection(); 
                Statement statement = con.createStatement()) {
            statement.setQueryTimeout(10);  // 10 seconds

            try (ResultSet rs = statement.executeQuery(
                    "select * " +
                    "from my_huge_table " + 
                    "where column_without_index = 'some Value'")) {
             
                 // do something with the result set 

            }
        }


the JDBC driver sends in both cases a "Statement.cancel()" request after the defined timeout. However, when I use the JDBC-Thin driver, the cancel Request has no effect and my statements keeps on running for many more minutes until it produces the requested result set. On the contrary when using the JDBC-OCI driver, I immediately get the expected "java.sql.SQLTimeoutException: ORA-01013" Exception.

Is there any way to configure the Thin driver that it handles cancellation requests as reliable as the OCI driver?

and Connor said...

With the thin driver, a lot depends on the version of the driver, and the platform you are running. In particular, Windows tends to have issues.

MOS note 850511.1 has an example of this, but make sure you are using the latest drivers you can. The thick driver then becomes the fallback option.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Query-Timeout works with Thin driver on Linux but not on Windows

Joern, August 15, 2019 - 9:22 am UTC

I can confirm that the query timeout is working with the 18.3 and the 19.3 driver via the Thin driver, if the client is running on a Linux system.
However, if the client runs on a Windows 7 system the query timeout has no effect when using the Thin driver. It is only functioning properly with the OCI driver on Windows.

In our case the Oracle DB Server itself runs always on a Linux server.
Connor McDonald
August 19, 2019 - 6:41 pm UTC

I think that MOS note states the same, ie, Windows = Nope