3

I'm trying to set up a connection pool using com.microsoft.sqlserver.jdbc.SQLServerXADataSourcein Tomcat8. While everything is fine using com.microsoft.sqlserver.jdbc.SQLServerDriver, when using SQLServerXADataSource, Tomcat claims No suitable driver found.

I'm sure that the correct driver jar is in $CATALINA\lib, however I am not sure if it is loaded correctly, as com.microsoft.sqlserver.jdbc.SQLServerDriver is working with and without that driver in lib. Maybe there is some other driver loaded which I could not locate.

Similar problem on Windows and OS X so far...

Does anyone know how to solve this?

UPDATE: Im setting up my datasource in-Code, like this:

//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  final ConnectionFactory                     connectionFactory         = new DriverManagerConnectionFactory(connectURI, null);
  final PoolableConnectionFactory             poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
  final GenericObjectPool<PoolableConnection> connectionPool            = new GenericObjectPool<>(poolableConnectionFactory);
  poolableConnectionFactory.setPool(connectionPool);
  return new PoolingDataSource<>(connectionPool);
gapvision
  • 999
  • 1
  • 10
  • 30
  • If `com.microsoft.sqlserver.jdbc.SQLServerDriver` is working even without the driver then are you using any build tool example maven or gradle? – zulqarnain Jul 01 '15 at 09:13
  • It will also be helpful if you show your configuration settings. – zulqarnain Jul 01 '15 at 09:21
  • @zulq I'm happy to provide any usefull Information, which configuration do you mean? `catalina.properties`? Yes, I'm using maven, and yes, the driver `sqljdbc4.jar` is also included in the war. But if Tomcat would use this one, it would be able to find `SQLServerXADataSource`, not? – gapvision Jul 01 '15 at 09:26
  • I mean your `/META-INF/context.xml`, that is where you should define your connection. – zulqarnain Jul 01 '15 at 09:35
  • Here's a link that shows an example: http://stackoverflow.com/questions/15498851/configure-sql-server-connection-pool-on-tomcat – zulqarnain Jul 01 '15 at 09:43
  • ah, I should have said that I do not use Resources but load my driver in the code... – gapvision Jul 01 '15 at 11:39

2 Answers2

1

This configuration should work. Make the necessary changes for the corresponding values:

<Resource name="jdbc/mssql" 
              auth="Container"
              type="com.microsoft.sqlserver.jdbc.SQLServerXADataSource"
              factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
              integratedSecurity="false"
              serverName="127.0.0.1"
              databaseName="yourDbName"
              portNumber="1433"
              user="username"
              password="pwd" />
zulqarnain
  • 1,695
  • 1
  • 16
  • 33
0

It seems there is no known way to do this in-code. However, I managed to set it up using

<Resource name="jdbc/mssql"
          auth="Container"
          type="javax.sql.XADataSource"
          driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          username="XXX"
          password="XXX"
          url="JDCB Connection String"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        />
gapvision
  • 999
  • 1
  • 10
  • 30