Hi When I try to connect to the datasource using JNDI, I am getting this error:

    [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)
    at org.apache.roller.weblogger.business.DatabaseProvider.getConnection(DatabaseProvider.java:179)
    at org.apache.roller.weblogger.business.DatabaseProvider.<init>(DatabaseProvider.java:141)
    at org.apache.roller.weblogger.business.startup.WebloggerStartup.prepare(WebloggerStartup.java:171)
    at org.apache.roller.weblogger.ui.core.RollerContext.contextInitialized(RollerContext.java:138)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
    at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
    at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
    at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
    at java.sql.DriverManager.getDriver(DriverManager.java:253)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
    ... 30 more]

Context.xml

<Context path="/roller" docBase="c:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\roller" debug="0">
    <Resource name="jdbc/rollerdb" auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/rollerdb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8-&amp;mysqlEncoding=utf8"
        username="roller_user"
        password="password"
        maxActive="20" maxIdle="3" removeAbandoned="true"
        maxWait="3000" 
    />
    <Resource name="mail/Session"
        auth="Container"
        type="javax.mail.Session"
        username="[email protected]"
        password="password"
        mail.debug="false"
        mail.user="[email protected]"
        mail.password="password"
        mail.smtp.from="[email protected]"
        mail.transport.protocol="smtp"
        mail.smtp.port="465"
        mail.smtp.host="smtp.gmail.com"
        mail.smtp.auth="true"
        mail.smtp.starttls.enable="true"
        mail.smtp.socketFactory.port="465"
        mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
        mail.smtp.socketFactory.fallback="false" 
    />
</Context>

web.xml

<web-app .. >
...
    <!-- jndi resources -->
    <resource-ref>
        <res-ref-name>jdbc/rollerdb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <resource-ref>
        <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

</web-app>

roller-custom.properties

installation.type=auto
database.configurationType=jndi
database.jndi.name=jdbc/rollerdb
mail.configurationType=jndi
mail.jndi.name=mail/Session

I've got mysql-connector-java-5.1.15-bin.jar, activation.jar and mail.jar in tomcat's lib diectory and the web application roller in tomcat's webapps folder.

I've not been able to understand what I am doing wrong here. Could someone help me understand what am I missing here?

Thanks.

Thanks.

4

There are 4 answers

0
Francisco Cifuentes-Silva On

I've solved this problem changing the import reference (in my case) from:

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

to

import org.apache.commons.dbcp.BasicDataSource;

My error was generated because I always use CRTL+o for import references, and when I made the import I had not the .jar in my references. I hope this may be useful for others.

1
demongolem On

I just got through a similar error and it turns out my context.xml file was slightly mangled. I think this most likely is where the problem resides.

My suggestion in comparing context.xml files between myself and you, I say try this

driverClass

In place of

driverClassName
0
karthic On

You could also encounter this error if your Tomcat version is different ..then ur context.xml would have to look different ...for detail go to this page ..a must read for this problem :

http://www.crazysquirrel.com/computing/java/connection-pooling.jspx

regs Karthic

0
Picrochole On

In my case helped following changes: in APPLICATION_PATH/WebContent/META_INF/context.xml

old code:

<resource name="jdbc/internships_db" auth="Container" type="javax.sql.DataSource">
    <param name="username" value="my_user" />
    <param name="password" value="my_password" />
    <param name="url" value="jdbc:mysql://localhost:3306/internships_db" />
</resource>

new code:

<Resource name="jdbc/internships_db"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="100"
    maxIdle="30"
    username="my_user"
    maxWait="10000"
    driverClassName="com.mysql.jdbc.Driver"
    password="my_password"  
    url="jdbc:mysql://localhost:3306/internships_db"/>

Jdbc-Driver class is placed under the path /user_path/tomcat-instance_path/webapps/app_name/WEB-INF/lib/com.mysql.jdbc_5.1.5.jar