jbm-ayesa
jbm-ayesa

Reputation: 31

Window 2008 Tomcat 7 MS SQL Server 2008R2 - JNDI JDBC Driver not recognized

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

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:

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

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?

Upvotes: 3

Views: 9251

Answers (1)

Vijay B
Vijay B

Reputation: 31

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> 

Upvotes: 0

Related Questions