3

First of all I must say that I've already looked for this problem and I've found several answers, none worked for me.

I have Tomcat 7 running as a service on Windows 2008 x64 with JDK 1.7.0.10.

I'm trying to use a JDBC Connection Pool, that I've successfully run in Tomcat 6.0.36 (Not installed as a service) on Windows 7 x86. The configuration was simple:

  1. Copy sqljdbc4.jar into %CATALINA_HOME%\lib directory.

  2. Edit %CATALINA_HOME%\webapps\APP_NAME\META-INF\context.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiJARLocking="true" path="/APP_NAME">
        <Resource name="jdbc/poolConexiones"
                auth="Container"
                driverclassname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
                maxactive="100"
                maxidle="30"
                maxwait="10000"
                username="user"
                password="pass"
                type="javax.sql.DataSource"
                url="jdbc:sqlserver://localhost:1433;databaseName=Name">
        </Resource>
    </Context>
    
  3. Edit web.xml:

    <resource-ref>
        <res-ref-name>jdbc/poolConexiones</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    

And it works fine!

However, when I tried to run the same application in

  • a) w2008 x64 and tomcat (v 6 and 7) installed as service
  • b) wXP x86 and tomcat (v 6 and 7) installed as service

following the same steps, I get:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

Then I tried different things:

  • Modify jvm's classpath on service laucher:

    Java Classpath: C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\sqljdbc4.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\tomcat-juli.jar

Works on WinXP, but it didn't work on w2008.

  • Use regular Tomcat version (not service), modify Catalina.bat in order to include sqljdbc4.jar in classpath:

    if "%CLASSPATH%" == "" goto emptyClasspath set "CLASSPATH=%CATALINA_HOME%\lib\sqljdbc4.jar;%CLASSPATH%;" :emptyClasspath set "CLASSPATH=%CATALINA_HOME%\lib\sqljdbc4.jar;%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"

    if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir set "CATALINA_TMPDIR=%CATALINA_BASE%\temp" :gotTmpdir

Works on WinXP, but it didn't work on w2008

So, after repeating several times the same steps in different order and trying different versions of tomcat an Java, I don't know what else to do.

Please, remember that this application is running with this configuration in w7 x86 and tomcat 6 through NetBeans 6.91 without any modification, and it runs on Win XP x86 editing the classpath.

What's the problem then?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jbm-ayesa
  • 31
  • 1
  • 5
  • I made it work uninstalling tomcat 7, downloading ZIP version, unzipping it in a different folder (avoiding Program files), creating a launcher.bat (wich sets CLASS_PATH pointing to "...\sqljdbc4.jar") and, after repeating libraries configuration... IT WORKED! – jbm-ayesa Jan 15 '13 at 18:30
  • Please refer below link, it worked for me https://stackoverflow.com/questions/2497725/connecting-to-ms-sql-through-hibernate/41045022#41045022 – Anksss May 11 '17 at 19:48
  • As far as I can tell, this problem is one of the case-sensitivity of XML configuration. It should have been `driverClassName` (and `maxActive`, `maxIdle` and `maxWait`). See also https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JDBC_Data_Sources – Mark Rotteveel May 16 '18 at 15:55

1 Answers1

0

On an additional note, if you have several instances of SQLServer running in your database service, you need to qualify the instance you are connecting to by providing the instanceName attribute in context.xml. In Tomcat 6, context.xml is at CATALINA_HOME/conf folder.

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/APP_NAME">
   <Resource name="jdbc/poolConexiones"
        auth="Container"
        driverclassname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
        maxactive="100"
        maxidle="30"
        maxwait="10000"
        username="user"
        password="pass"
        type="javax.sql.DataSource"
      url="jdbc:sqlserver://localhost:1433;instanceName=myInstance;databaseName=Name">
   </Resource>
</Context> 
Vijay B
  • 31
  • 5