Godaddy JNDI Problem---Cannot create JDBC driver o

2019-04-15 15:27发布

问题:

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?



标签: java jndi