Using with SQL Server

1,475 views
Skip to first unread message

Wickman

unread,
Feb 27, 2014, 5:19:45 AM2/27/14
to hika...@googlegroups.com
Hi

Anyone tested Hikari with SQL Server?

What class should I use when configuring Hikari with SQL Server?

SQLServerConnectionPoolDataSource or SQLServerDriver?

I'm confused here.

How do I set the URL properly?

When trying this:

   hikariConfig.setDataSourceClassName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource");
   hikariConfig.addDataSourceProperty("url", "jdbc:sqlserver://host:1433;databaseName=mydb;user=myuser;password=mypwd");

I get this:

   Exception in thread "main" java.lang.RuntimeException: Could not create datasource instance:    
   com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource
     ...
   Caused by: java.lang.RuntimeException: java.beans.IntrospectionException: Method not found: setUrl


The MS docs are here btw.

Cheers!

Brett Wooldridge

unread,
Feb 27, 2014, 6:14:37 AM2/27/14
to hika...@googlegroups.com
You should be able to use com.microsoft.sqlserver.jdbc.SQLServerDataSource.  The error you
are seeing for setUrl is caused by a simple capitalization issue, the method is setURL() so the
datasource property would be URL instead of Url.  However, with a DataSource the URL is
entirely optional and you can do everything through properties ... which I find clearer to read.

See this example for initializing the DataSource solely through properties:


Essentually, drop the 'set' off of any setter to use it as a property in HikariCP.

Brett Wooldridge

unread,
Feb 27, 2014, 7:11:23 AM2/27/14
to hika...@googlegroups.com
Most of the properties (setters) defined here can be configured through datasource properties in HikariCP:


Wickman

unread,
Feb 27, 2014, 8:05:51 AM2/27/14
to hika...@googlegroups.com
Thanks for you input.

I got it to work with SQLServerDataSource and addDataSourceProperty("URL","..."l). 

By the way, I also tried with SQLServerConnectionPoolDataSource, and it seems to work just as well.

Brett Wooldridge

unread,
Feb 27, 2014, 8:35:20 AM2/27/14
to hika...@googlegroups.com
Great, glad you got it working.

Both DataSources will work exactly the same in HikariCP.  SQLServerConnectionPoolDataSource implements the JDBC ConnectionPoolDataSource interface, which can provide a event driven callbacks for conditions like connection close, but HikariCP doesn't use them (nor do most pools) because for many drivers they are not well implemented.  Connection testing and exception inspection provide the most reliable methods for checking "aliveness".  The ConnectionPoolDataSource might impose a slight overhead compared to the pure SQLServerDataSource but I would not expect it to be easily measured even with a microbenchmark, so we're talking about a few microseconds difference at connection close.  Use whichever one you are comfortable with.

-Brett

Reply all
Reply to author
Forward
0 new messages