Configure SQL Server connection pool on Tomcat

41,117

Solution 1

We found our problem.

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

Should have been

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

Solution 2

It seems to me that the java side is correctly configured.

Can you access the server using another JDBC connection (for example SquirrelSQL or similar software)?

If you can't access to the server using Squirrel, maybe you did not enable the TCP/IP access to your server, in this case, follow the accepted answer of Enable remote connections for SQL Server Express 2012

Share:
41,117
fcm
Author by

fcm

coding software and changing lives

Updated on February 23, 2020

Comments

  • fcm
    fcm about 4 years

    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.

  • fcm
    fcm about 11 years
    That definitely had some effect! However, I'm now receiving the following message: Mar 19, 2013 10:50:57 AM org.apache.naming.NamingContext lookup Warning: Unexpected exception resolving reference java.sql.SQLException at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDri‌​ver(PooledConnection‌​.java:254)
  • Carlo Pellegrini
    Carlo Pellegrini about 11 years
    I need more lines on the stack trace, could you edit your post, attaching the full exception you are getting?
  • fcm
    fcm about 11 years
    I've added it to the original post