Search code examples
javasql-servertomcattomcat7connection-pooling

Configure SQL Server connection pool on Tomcat


I've been trying to configure a connection pool for a SQL Server 2012 database. I currently have Informix and Oracle pools configured and working, only SQL Server is giving me a headache. This is how my resource on Context.xml looks so far:

<Resource name="jdbc/sqlserv"
    auth="Container"
    factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    type="javax.sql.DataSource"
    maxActive="50"
    maxIdle="10"
    maxWait="15000"
    username="username"
    password="password"
    url="jdbc:sqlserver://127.0.0.1:1433;databaseName=SQLDB;"
    removeAbandoned="true"
    removeAbandonedTimeout="30"
    logAbandoned="true" /> 

That's using sqljdbc4 driver, of course. We already tried using jtds-1.3.0 with the driverClass="net.sourceforge.jtds.jdbc.Driver", but no go. All the resource-refs are also being correctly configured. Whenever I try to create a new connection using that Resource, it fails.
For comparison's sake, here's how our Informix and Oracle resources look like:

<Resource name="jdbc/infmx"
    auth="Container"
    type="javax.sql.DataSource"
    factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    maxActive="50"
    maxIdle="10"
    maxWait="15000"
    username="username"
    password="password"
    driverClassName="com.informix.jdbc.IfxDriver"
    url="jdbc:informix-sqli://localhost:30091/infmx:informixserver=ol_infmx_soc"
    removeAbandoned="true"
    removeAbandonedTimeout="30"
    logAbandoned="true"/>

<Resource name="jdbc/orcl"
    auth="Container"
    type="oracle.jdbc.pool.OracleDataSource"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    factory="oracle.jdbc.pool.OracleDataSourceFactory"
    url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
    user="username"
    password="password"
    maxActive="50"
    maxIdle="10"
    maxWait="15000" /> 

So My question is: How can I correctly configure a connection pool for SQL Server 2012 on my tomcat context? I've searched high and low, attempted everything I've found, but nothing worked.


Thanks in advance.

[edit] Here's the stack trace: http://pastebin.com/w3rZSERs

[edit-2] It seems the problem is that Tomcat can't find the driver on his lib folder. We're pretty sure it's there, but we don't know to be sure of that. This happens with both sqljdbc4 and jtds-1.3.0. We're following every guideline we can find, but the problem persists.


Solution

  • We found our problem.

    driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    

    Should have been

    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"