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.
For configuring the connection pool for SQLServer you need to configure the SQLServer drivers as explained in the Microsoft SQL Server section and put the jar file into the TOMCAT_HOME/lib folder. Note that database name, username and password must be defined directly in the URL.
Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself. Tomcat jdbc pool is a Tomcat module, it depends on Tomcat JULI, a simplified logging framework used in Tomcat. Retrieve the underlying connection using the javax. sql.
Application context. xml - This is the easiest way to configure DataSource, all we need is a context. xml file in META-INF directory. We have to define Resource element in the context file and container will take care of loading and configuring it.
Tomcat provides a JNDI InitialContext implementation instance for each web application running under it, in a manner that is compatible with those provided by a Java Enterprise Edition application server. The Java EE standard provides a standard set of elements in the /WEB-INF/web.
We found our problem.
driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
Should have been
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With