Advertisement

04.12.2004 at 04:55PM PDT, ID: 20951693
[x]
Attachment Details

Tomcat - Connection error from DataSource using JNDI

Asked by topher1120 in Application Servers

Tags: tomcat, jndi, connect

Hi, I'm trying to connect to an Oracle 8i database using JNDI lookup from Tomcat 4.1.30 and get an error I can't figure out.

The error message reads: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
This error seems to be when I try to get a connection from the DataSource object:
Connection conn = datasource.getConnection();

In attempts to figure this out, I created a test servlet that first connects to the database using the hard-coded driver and url, then JNDI.

The servlet doGet looks like this:
                  protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            
            PrintWriter out = response.getWriter();
            String sDriver = "oracle.jdbc.driver.OracleDriver";
            String sURL = "jdbc:oracle:thin:@somecompany.com:1521:db1";
            try {
                  out.println("Attempting Oracle connection<br>");
                  Class.forName(sDriver).newInstance();
                  Connection conn = DriverManager.getConnection(sURL, "scott", "tiger");
                  conn.close();
                  out.println("Connected to Oracle okay<br>");
            
            } catch (InstantiationException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            } catch (IllegalAccessException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            } catch (ClassNotFoundException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            } catch (SQLException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            }
            
            InitialContext ctx;
            try {
                  out.println("Attempting JNDI connection<br>");
                  ctx = new InitialContext();
                  Context envctx = (Context) ctx.lookup("java:comp/env");
                  DataSource datasource = (DataSource) envctx.lookup("jdbc/operations");
                  Connection conn = datasource.getConnection();
                  conn.close();
                  out.println("Connected to JNDI okay<br>");
            }
            catch (NamingException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            } catch (SQLException e) {
                  out.println(e.getClass()+": "+e.getMessage()+"<br>");
            }
            
      }

The output looks like this:
Attempting Oracle connection
Connected to Oracle okay
Attempting JNDI connection
class org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

My server.xml looks like:
...
<GlobalNamingResources>
    <Environment name="simpleValue" override="true" type="java.lang.Integer" value="30"/>
     <Resource auth="Container" name="jdbc/operations" scope="Shareable" type="javax.sql.DataSource"/>
     <ResourceParams name="jdbc/operations">
        <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>
        <parameter>
            <name>driverClassName</name>
            <value>oracle.jdbc.driver.OracleDriver</value>
        </parameter>
        <parameter>
            <name>url</name>
            <value>jdbc:oracle:thin:@somecompany.com:1521:db1</value>
        </parameter>
        <parameter>
            <name>username</name>
            <value>scott</value>
        </parameter>
        <parameter>
            <name>password</name>
            <value>tiger</value>
        </parameter>
        <parameter>
            <name>maxActive</name>
            <value>20</value>
        </parameter>
        <parameter>
            <name>maxIdle</name>
            <value>10</value>
        </parameter>
        <parameter>
            <name>maxWait</name>
            <value>5000</value>
        </parameter>
      </ResourceParams>

  </GlobalNamingResources>
...

My web.xml looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
      <!-- define global vars -->
      
      
      <servlet>
     <servlet-name>TestServlet</servlet-name>
     <servlet-class>testJNDI.TestJNDI</servlet-class>
    </servlet>
   
      <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/servlet/TestJNDI</url-pattern>
    </servlet-mapping>
      
      <session-config>
            <session-timeout>120<!-- in minutes --></session-timeout>
      </session-config>
      <resource-ref>
            <description>Oracle Datasource</description>
             <res-ref-name>jdbc/operations</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
</resource-ref>

      
</web-app>


Help!

Thanks in advance.Start Free Trial
 
 
Loading Advertisement...
 
[+][-]04.13.2004 at 07:59AM PDT, ID: 10814080

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.13.2004 at 09:13AM PDT, ID: 10814850

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.13.2004 at 10:36AM PDT, ID: 10815656

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.13.2004 at 12:03PM PDT, ID: 10816443

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.13.2004 at 12:22PM PDT, ID: 10816588

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.13.2004 at 03:04PM PDT, ID: 10818073

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.14.2004 at 11:44PM PDT, ID: 10830605

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2004 at 02:13PM PDT, ID: 10837121

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2004 at 03:51PM PDT, ID: 10837824

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2004 at 04:01PM PDT, ID: 10846719

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 02:41PM PDT, ID: 11044957

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05.15.2004 at 07:02AM PDT, ID: 11075836

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Application Servers
Tags: tomcat, jndi, connect
Sign Up Now!
Solution Provided By: modulo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]02.15.2005 at 09:27AM PST, ID: 13316061

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.15.2005 at 09:40AM PST, ID: 13316183

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32