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

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

Related

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

How to fix "no ocijdbc12 in java.libary.path" on Oracle SQL Developer?

I try to access DB server by Oracle SQL Developer then I found following display below.
I try to fixed on other posts already but it didn't work.
There are two ways to fix this:
don't make a connection request that is trying to pull in the OCI library - in other words, stay with JDBC THIN
configure SQL Developer such that your Oracle Client can be loaded for a THICK (OCI) connection
Option 1:
In your connection properties, if you're using TNS, use a Network Alias, NOT a Connect Identifier.
Otherwise, as long as you do not have 'Use OCI' enabled in your advanced connection properties or Advanced Database Preferences, you should have a THIN connection.
Option 2:
Go into the preferences and correctly configure the Oracle Client section of the Advanced Database page.
I talk about this in more detail here.

tomcat 8.5.x tomcat-jdbc.jar vs official oracle ojdbc6.jar driver

I'm struggling with jdbc connection to oracle database, which should I use?
The tomcat-jdbc.jar (inside tomcat) or oracle ojdbc6.jar (official by oracle)
What are the difference between the two driver?
(ojdbc6 version 11.2.0.4 guarantee to me to work with oracle 12c db and oracle 10 db could do the same the tomcat-jdbc.jar??)
Actually, they are different libraries. tomcat-jdbc.jar is the default Tomcat connection pool (in Tomcat version 8.5) and it's responsible for managing connections, allowing you fast access to already created ones, whereas ojdbc6.jar is your actual JDBC driver from Oracle that provides database connectivity to Oracle Database server.
Other words, you cannot use tomcat-jdbc.jar alone in case you want to "talk" to your Oracle Database, but it's possible to use ojdbc6.jar without pooling, although it's not recommended due to perfomance drop in most cases.
Here is a good explanation:
ojdbc6.jar -
What is ojdbc6.jar file?
Connection Pool - https://en.wikipedia.org/wiki/Connection_pool

how to implement sql server connection pooling in java jdbc?

I tried to search for this but it seems the answer might now be true anymore. How can do connection pooling in java with sql server? I found the new jdbc driver of microsoft but there's no sample code to show to use it.
Microsoft MSSQL-JDBC is now open sourced. You can see test cases used Hikari & Apache DBCP connection pool.
One can see PoolingTest.java and methods testApacheDBCP and testHikariCP.
For HikariCP and DBCP

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.

Categories

Resources