how to implement sql server connection pooling in java jdbc? - java

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

Related

How do I connect SQL*Plus with Java using netbeans? [duplicate]

what are the drivers which are used to connect with java for Desktop application. i have found many types like tiny and all but was not able to understand.
Please help me out
To make your life easier, I would recommend just using Oracle's Thin Driver.
First, download the driver from Oracle's site:
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Then add JAR to your project and connect to database using:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
Of course, replace these parameters with the ones corresponding to your DB.
Have you looked into official site
See Also
JDBC kick start
for oracle 10g the JDBC driver is "ojdbc10_g.jar"
it is available on your system inside %ORACLE_HOME\jdbc\lib
No need to download.
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
conn.setAutoCommit(false);
The "thin" driver is a 100% java implementation. The OCI calls the C implementation. There might even be a JDBC to ODBC bridge, allowing you to use your system's ODBC driver. Suggested reading: Oracle Instant Client
The easiest one to deploy is probably the type 4 driver, or the thin driver. I say it is the easiest because it does not rely on any Oracle native libraries or client install to operate. It is readily available from Oracle.

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.

How to use Universal Connection Pool (UCP) with Sybase?

Trying to configure connection pooling in standalone Java application.
Using UCP and Sybase DB. I am stuck at Connection Factory ClassName to use for Sybase.
Tried using com.sybase.jdbc4.jdbc.SybConnectionPoolDataSource but with no success.
It's just like using a Connection from some props file, except you create a DataSource Object first, then retrieve your connection from the DataSource. I can't give you a better example than is in the Sybase documentation here...
Jconnect 7 (Jconn4) docs...Scroll to page 9

Oracle 10g connection with Java

what are the drivers which are used to connect with java for Desktop application. i have found many types like tiny and all but was not able to understand.
Please help me out
To make your life easier, I would recommend just using Oracle's Thin Driver.
First, download the driver from Oracle's site:
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Then add JAR to your project and connect to database using:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
Of course, replace these parameters with the ones corresponding to your DB.
Have you looked into official site
See Also
JDBC kick start
for oracle 10g the JDBC driver is "ojdbc10_g.jar"
it is available on your system inside %ORACLE_HOME\jdbc\lib
No need to download.
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
conn.setAutoCommit(false);
The "thin" driver is a 100% java implementation. The OCI calls the C implementation. There might even be a JDBC to ODBC bridge, allowing you to use your system's ODBC driver. Suggested reading: Oracle Instant Client
The easiest one to deploy is probably the type 4 driver, or the thin driver. I say it is the easiest because it does not rely on any Oracle native libraries or client install to operate. It is readily available from Oracle.

Categories

Resources