Godaddy JNDI Problem---Cannot create JDBC driver of class '' for connect URL 'null'

蓝咒 提交于 2019-12-06 12:54:12

问题


I have a website hosted at Godaddy where I use JNDI to manage DB connections. Godaddy is using Tomcat 5.5.27 with JDK 1.5. I am also using the same versions locally.

JNDI works fine at my local development environment, but when I run it at Godaddy, I get the following exception message:

Cannot create JDBC driver of class '' for connect URL 'null'

I have placed everything correctly in Godaddy server as in my local system.

Here is the context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Specify a JDBC datasource -->

        <Resource
    name="jdbc/interviewzone"
    auth="Container"
    type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/interviewzone">
    <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
        <name>driverClassName</name>
        <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
        <name>url</name>
        <value>someurl</value>
    </parameter>
    <parameter>
        <name>username</name>
        <value>root</value>
    </parameter>
    <parameter>
        <name>password</name>
        <value>root</value>
    </parameter>
    <parameter>
        <name>maxActive</name>
        <value>20</value>
    </parameter>
    <parameter>
        <name>maxIdle</name>
        <value>10</value>
    </parameter>
    <parameter>
        <name>maxWait</name>
        <value>-1</value>
    </parameter>
    <parameter>
        <name>removeAbandoned</name>
        <value>true</value>
    </parameter>
    <parameter>
        <name>removeAbandonedTimeout</name>
        <value>300</value>
    </parameter>
    <parameter>
        <name>logAbandoned</name>
        <value>true</value>
    </parameter>
</ResourceParams>
</Context>

Here is the relevant part of my Java code:

Context initContext = new InitialContext();
DataSource dataSource = (DataSource) initContext.lookup("java:/comp/env/jdbc/interviewzone");
Connection conn = dataSource.getConnection(); // This throws exception.

I have included the resources in web.xml. Because it runs locally fine, I think that there is no problem in the code. I have contacted Godaddy, but they are technically weak. They told that the problem is in my code, but I don't agree with them because it is running locally fine.


回答1:


You need to make sure that jar file containing the driver class that you need (com.mysql.jdbc.Driver) is in your WEB-INF/lib folder.

How are you deploying it to Godaddy?



来源:https://stackoverflow.com/questions/3717870/godaddy-jndi-problem-cannot-create-jdbc-driver-of-class-for-connect-url-nu

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