HikariCP with Oracle and ojdbc6.jar

5,172 views
Skip to first unread message

Ryan Asleson

unread,
Feb 27, 2014, 9:21:23 AM2/27/14
to hika...@googlegroups.com

Hello,

I'm attempting to use HikariCP in a Tomcat 7 environment.  Please bear with me as this message is pretty long but I'm just trying to be complete.

I want to use HikariCP in Tomcat 7 pointing to Oracle, using the ojdbc6.jar file that is in the Tomcat classpath.

I downloaded the zip file from the website (http://brettwooldridge.github.io/HikariCP/) and did the Maven build.  The output was HikariCP-1.3.1-SNAPSHOT.jar which I put in my web app's WEB-INF/lib directory.  I'm don't know much about Maven but the build seemed to work.

I got through the configuration, but when I try to create the HikariDataSource instance, it throws an error.  I think the error is due to the dataSourceClassName property being incorrect.  I've tried a few things and here is what happened.

First, I simply had oracle.jdbc.OracleDriver in as the dataSourceClassName, because this is the class name that I have in context.xml for the Tomcat connection pool.  That failed and the error message said that the class is not an instance of DataSource.  Big "duh" on my part.

Next, I tried oracle.jdbc.xa.client.OracleXADataSource as this seemed to pop up in the web search.  This failed with a RuntimeException with this message: "Could not create datasource instance: oracle.jdbc.xa.client.OracleXADataSource".  Digging further, the cause was this: java.beans.IntrospectionException: Method not found: setUrl

Lastly, I tried oracle.jdbc.xa.OracleXADataSource, just because I saw that class in the Oracle jar.  That failed too:  InstantiationException Could not create datasource instance: oracle.jdbc.xa.OracleXADataSource

I've run out of ideas.  Any idea what I'm doing wrong?  It looks like it's close but I'm not setting something right.

Thank you for your help!!!

-Ryan


Brett Wooldridge

unread,
Feb 27, 2014, 9:37:34 AM2/27/14
to hika...@googlegroups.com
The XA datasource is only for use with JTA transaction managers like Bitronix or Atomicos.  The class you want is oracle.jdbc.pool.OracleDataSource.

For performance, you probably also want to set the datasource property implicitCachingEnabled=true.

-Brett

Ryan Asleson

unread,
Feb 27, 2014, 10:16:29 AM2/27/14
to hika...@googlegroups.com

Hey!  That seemed to work!!  Thank you!!

I haven't actually tested a connection from it yet (the app is still using connections from the Tomcat pool) but to be able to create the HikariDataSource without error is a huge step.

For those who might stumble upon this later, I had to tweak a few of the properties in the data source properties file.  For example, the property is "user" not "userName" and the URL property has to be in all caps.  Here is a sliver of what worked for me:

dataSourceClassName=oracle.jdbc.pool.OracleDataSource
dataSource.user=yourusernamehere
dataSource.password=yourpasswordhere
dataSource.URL=jdbc:oracle:thin:@yourservername:1521:yourdatabasename
dataSource.implicitCachingEnabled=true

Although I am seeing this in the Tomcat console:'

Exception in thread "Hikari Housekeeping Timer" java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariPool$AddConnectionStrategy
at com.zaxxer.hikari.HikariPool$HouseKeeper.run(HikariPool.java:569)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariPool$AddConnectionStrategy
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 3 more

Not sure if it is a big problem.  

Brett Wooldridge

unread,
Feb 27, 2014, 10:29:54 AM2/27/14
to
I'm glad you got it started at least.  You don't need to use the URL.  With a DataSource the URL is entirely optional and everything can be configured via properties.  I find it much more readable that way.  For example, there is a serverName property, databaseName property, portNumber property, etc.

Re: the exception.  That is a very strange error indeed.  The HouseKeeper and AddConnectionStrategy are both inner classes of HikariPool.  It should not be possible for the HouseKeeper to be instantiated and yet the AddConnectionStrategy class not be found.  It sounds like a classpath issue of some kind.  Is the JAR file in two places?  For example, in the tomcat libs directory as well as the WAR libs directory?

You might try the official release version, rather than the one you built which is the development snapshot. You can download it from the Maven Central repository here:


HikariCP-1.3.0.jar is what you want.

-Brett

I'm off to bed, it's 12:30am here in Tokyo.

Reply all
Reply to author
Forward
0 new messages