简体   繁体   中英

jdbc DB2 queryTimeout not working as expected

We are facing issue with the the query timeout property on Db2, it is working when we are running the app in WebSphere, then we moved to Tomcat, this issue was recently caught up by a very long query that hangs very long until timeout after 45 minutes, some pieces of the code we have as below, they haven't been changed since moving to Tomcat:

    CallableStatement cs = statementFactory.createCallableStatement(getConnection(), source.getSQL(),
                statementConfig);
    cs.setQueryTimeout(10);
    boolean resultSetAvailable = cs.execute();
    if (resultSetAvailable) {
            resultSet = cs.getResultSet();
        } else {
            resultSet = CallableStatementParamsUtils.checkForOutResultSet(cs, storedProc);
        }

  • I set up the timeout to be 10 secs, but it didn't timeout at all, anybody knows why?

  • The difficulty is Db2 driver is not open source, not able to debug it, How can I solve this issue using Db2?

In this case, the use of a jdbc type 4 driver appeared to help to resolve the issue.

Note that the IBM db2 jdbc driver supports tracing for problem determination as described here .

When dealing with jdbc issues with Db2, it is always helpful to ensure you are using the most recent jdbc driver, available via this page .

From the comments, the previous jdbc driver was a type-2 driver (which supports query timeouts only in specific configurations as IBM documents in the Db2 knowledge center, the notes are copied below).

The various IBM notes on this page concerning queryTimeout support in jdbc are essential reading , viz:

  • For DB2 for i, this method (setQueryTimeout) is supported only for a seconds value of 0.

  • For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity on Db2 for z/OS, Statement.setQueryTimeout is supported only if Connection or DataSource property queryTimeoutInterruptProcessingMode is set to INTERRUPT_PROCESSING_MODE_CLOSE_SOCKET.

  • For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity on Db2 on Linux, UNIX, and Windows systems, Statement.setQueryTimeout is supported only if Connection or DataSource property queryTimeoutInterruptProcessingMode is set to INTERRUPT_PROCESSING_MODE_STATEMENT_CANCEL.

  • For the IBM Data Server Driver for JDBC and SQLJ Version 4.0 and later, Statement.setQueryTimeout is supported for the following methods:

    Statement.execute Statement.executeUpdate Statement.executeQuery

  • Statement.setQueryTimeout is supported for the Statement.executeBatch method only when property queryTimeoutInterruptProcessingMode is set to INTERRUPT_PROCESSING_MODE_CLOSE_SOCKET (2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM