Configure SQL Server connection pool on Tomcat

孤者浪人 提交于 2019-12-29 04:59:15

问题


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.


回答1:


We found our problem.

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

Should have been

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



回答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



来源:https://stackoverflow.com/questions/15498851/configure-sql-server-connection-pool-on-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!