Hi folks,

Ok, I'm using Tomcat 4.0.1, and am trying to access a JDBC datasource via
JNDI. I've tried to study the docs before asking stupid questions, but I'm
completely stuck right now and am hoping someone can see what I'm doing
wrong.

The primary resources that I've been using include:
1. http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
2. http://www.j-netdirect.com/JSQLTechRef.htm#J2EE_DataSource

Based on the instructions, my server.xml defines a resource like this:

        <!-- Test99 Context -->
        <Context path="/Test99" docBase="E:\Test99" debug="1">
          <Resource name="jdbc/Test99DB" auth="Container"
type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/Test99DB">
                <parameter>
                    <name>database</name><value>pubs</value>
                </parameter>
                <parameter>

<name>driverClassName</name><value>com.jnetdirect.jsql.JSQLDataSource</value
>
                </parameter>
                <parameter>
                    <name>driverName</name><value>jdbc:JSQLConnect:</value>
                </parameter>
                <parameter>
                    <name>user</name><value>sa</value>
                </parameter>
                <parameter>
                    <name>password</name><value></value>
                </parameter>
          </ResourceParams>
        </Context>

My Test99 webapp's web.xml in turn defines a resource like this:

    <resource-ref>
        <description>Sample JDBC Resource</description>
        <res-ref-name>jdbc/Test99DB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

And finally, my servlet code looks like this:

        initCtx = new InitialContext();
        envCtx = (Context) initCtx.lookup("java:comp/env");
        ds = (DataSource) envCtx.lookup("jdbc/Test99DB");

When I run this, initCtx and envCtx both seem to get loaded properly
(they're not null). When I try to lookup the DataSource, however, it always
comes back as null. When I add some debugging stmts, like this:

        System.out.println("initCtx:"+initCtx);
        System.out.println("envCtx:"+envCtx);
        NamingEnumeration enum = envCtx.list("jdbc/");
        while (enum.hasMore()) {System.out.println(" --> "+enum.next());}
        System.out.println("ds:"+ds);

here's the output I get:

        initCtx:javax.naming.InitialContext@5ddb6e
        envCtx:org.apache.naming.NamingContext@71235b
         --> Test99DB: org.apache.naming.ResourceRef
        ds:null

So it looks like JNDI is working and the resource is available; why then is
ds coming back as null? Am I doing something stupid? I'm really confused on
this one; if you have any suggestions I'd love to hear from you.

tia,
Christian
----------------------------------------------
Christian Cryder [[EMAIL PROTECTED]]
Internet Architect, ATMReports.com
Barracuda - http://barracuda.enhydra.org
----------------------------------------------
 "What a great time to be a(n employed) Geek"


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to