jdbc DB2 queryTimeout not working as expected - java

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).

Related

How to connect to Oracle9i with SQLDeveloper 21?

I want to connect to an old Oracle9i Release 9.2.0.4.0 database with SQLDeveloper 21.4.3 and I followed this answer How to change default JDBC driver of Oracle SQL Developer?.
The difference is just the versions of SQLDeveloper (21 instead of 20) and Oracle Instant Client (21.3 instead of 11.2.0.4.0). In my case both are the latest ones.
My OS is also Windows 10, 64bit.
Testing the client and connection as described are successful. But when actually connecting to the database SQLDeveloper hangs and can only be closed by TaskManager.
I tried both connection types: simple and with user defined URL jdbc:oracle:thin:#172.31.10.3:1521:LZH. This URL works in other applications like SQL Workbench/J using oracle driver ojdbc14_g.jar.
I also tried to set this jar file in SQLDeveloper preferences as external jdbc driver. But I guess here only non oracle drivers like postgreSQL make sense, but don't know. It doesn't make a difference anyway.
Thanks for any suggestion!
You cannot connect an Oracle Client version 21 to an (more than 20 years old) Oracle 9i database. See Client / Server Interoperability Support Matrix for Different Oracle Versions
Maybe ask Oracle support to get an older version of SQL Developer.
Oracle provided me a link for older
Instant Client Versions.
Version 11.2 works fine with SQLDeveloper 20.2.
SQLDeveloper 21 only supports client versions 19 and higher.

HikariCP statement caching on MS SQL (microsoft JDBC driver 4.1)

How can I enable statement caching in MS SQL RDBMS for HikariCP connection pool ?
For MySQL it is via :
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048
For PostgreSQL via:
hikari.dataSource.prepareThreshold=1
For Oracle, the following works:
dataSource.implicitCachingEnabled=true
and adjusting via setMaxStatements() method of OracleDataSource
But I have not found anything for MS SQL 2012 and up.
Statement caching has to be provided by the database driver, HikariCP does not provide any statement caching. And as far as I can see (*), neither does the "Microsoft JDBC Driver for SQL Server". This leaves the option to use the alternative database driver jTDS. The jTDS home page does not indicate compatability with MS SQL 2012 but, the sourceforge project page does (I have not used jTDS so I am assuming the project page is more up to date (**)).
By default the jTDS driver caches 500 statements per connection (see the comments about maxStatements on the FAQ page).
Instead of using the dataSourceClassName com.microsoft.sqlserver.jdbc.SQLServerDataSource, use net.sourceforge.jtds.jdbcx.JtdsDataSource (also mentioned on this page which also indicates HikariCP was tested with the jTDS driver).
(*) The options available for the SQLServerDataSource are documented in ISQLServerDataSource but I could not find any options for statement caching.
(**) Encouraging comment in one of the last bug-reports: "We are using jTDS 1.3.1 with SQL Server 2014 with no issues."

JDBC Connection String with selectMethod=cursor breaks connection

I'm trying to deploy a JBoss webapp that requires selectMethod=cursor in the jdbc driver connection string.
But when I try connecting to my mssql (2008) database with this in the string, it just timesout when connecting. When I remove selectMethod=cursor from my connection string, it works/connects, but my app doesn't work and gives me this error: [SQLServer JDBC Driver]Can't start a cloned connection while in manual transaction mode.
I have already updated my jdbc driver - tested all versions.
Here is my connection string:
jdbc:microsoft:sqlserver://127.0.0.1:1434;DatabaseName=xxxx;user=xxxx;password=xxxxx;selectMethod=cursor
Thanks.
I switched from using a microsoft jdbc driver to jtds jdbc driver and it works wonderfully again.
Do the Microsoft docs on the issue shed any light on this?
This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver.
Resolution is:
When you use manual transaction mode, you must set the SelectMethod property of the driver to Cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article.

Java oci db connection failover with Oracle 9

We need the ability to failover from one database host to the other in the case that the one we’re currently connected to goes down. From what we’ve read, “Transparent Application Failover (TAF)” and “Fast Connection Failover (FCF)” are only available on Oracle 10 and higher. But our environment has Oracle 9.2.0.8.
What would be the best java solution to ensure our database connections failover? Using the oci driver seems to a better solution than the thin driver, however, we keep getting the “Unsatisfied Link Error: ocijdbc11.dll not on java.library.path”. We don’t have ocijdbc11.dll, but we do have ocijdbc10.dll in ${ORACLE_HOME}/bin
Environment:
Database = Oracle 9.2.0.8 with a RAC supporting two servers
Server = Solaris 10
Clients = Windows XP, service pack 3
JDK = 1.6.0_20
Library = ojdbc6.jar
Clients have Oracle thick client
10.1.0.2 installed. This gives them ocijdbc10.dll in their oracle bin directory
Our connection string in tnsnames.ora:
MY_SID =
(DESCRIPTION=
(FAILOVER=on)
(ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=db.fully.qualified.name)
(FAILOVER_MODE=
(TYPE=select)
(METHOD=basic))))
We create a datasource as follows:
BasicDataSource ds = new
BasicDataSource();
ds.setUsername(“username”);
ds.setPassword(“password”);
ds.setUrl(“jdbc:oracle:oci:#MY_SID”);
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
If you're getting “Unsatisfied Link Error: ocijdbc11.dll not on java.library.path” against a 10g client, sounds like you're using the 11g jdbc drivers. You need to use the 10g jdbc drivers.

Streaming large result sets with MySQL 4.1.x + Connector/J

I'm trying to get a large result set to stream and having no luck. The MySQL docs are somewhat unclear as to whether this should even work. E.g.:
When using versions of the JDBC driver earlier than 3.2.1, and connected to server versions earlier than 5.0.3, the `setFetchSize()` method has no effect, other than to toggle result set streaming as described above.
I'm using MySQL 4.1.19 with Connector/J 5.1.6. My code is basically:
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(Integer.MIN_VALUE);
stmt.executeQuery(“select * from huge_table”);
Are streaming result sets possible with MySQL 4.1.x? And if so, how?
What you are looking for is called "unbuffered query" in MySQL lingo, but a quick search seems to indicate that:
MySQL only supports it starting from version 5.0
JDBC doesn't support it

Categories

Resources