I had a similar problem, but i was using classes12.zip that is from Oracle.
I tried every option, but it didnt seem to work. Then at the end upgraded to
tc 4.1.7. TC 4.1.7 had all the included files, and got the DataSource and
the connection.
My advice, upgrade to TC 4.1.7 (AFAIK) it has much better support for JNDI.
Anyways there has been a lot of discussion about this in the past weeks. You
could check out the archives also. Check this link also.

http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2

Regards,
Vikramjit Singh,
Systems Engineer,
GTL Ltd.
Ph. 7612929-1059


-----Original Message-----
From: Turner, John [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 19, 2002 5:05 AM
To: 'Tomcat Users List'
Subject: RE: Datasource JNDI lookup failing



I've had the exact same problem with for the past couple of weeks, only with
the Microsoft Type4 SQL Server driver.  Everything seems to work great, and
the Context is definitely found, but the DataSource is always null.

I haven't been able to find a solution, the closest I came was going to
4.1.7, but I can't do that until it is officially released (my client has a
no betas restriction for production apps).

If anyone knows for sure how to get around this problem using current
production versions, I would love to know about it.

John Turner
[EMAIL PROTECTED]


-----Original Message-----
From: Adam Lipscombe [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 19, 2002 7:57 AM
To: Tomcat Users Mailing List
Subject: Datasource JNDI lookup failing


Folks,

I am having a problem trying to lookup a Database connection from JNDI with
Tomcat 4.0.4 on Debian Linux.
My code is:

    Connection con = null;

    System.out.println("instantiating database connection ");

    try
    {
      System.out.println("getting InitialContext");
      Context ctx = new InitialContext();
      System.out.println("got InitialContext");

      // Print out bindings to make sure its there
      NamingEnumeration e = ctx.list("java:comp/env/jdbc");
      while(true == e.hasMore())
      {
        System.out.println("enumeration name = " + e.next());
      }

      // Get JDBC context
      System.out.println("getting JDBC context");
      Context jdbcContext = (Context) ctx.lookup("java:comp/env/jdbc");
      System.out.println("got jdbcContext");

      // Look up our data source
      System.out.println("looking up insuranceAdminTest");
      DataSource ds = (DataSource) jdbcContext.lookup("insuranceAdminTest");
      System.out.println("got DataSource");

      con = ds.getConnection();
      System.out.println("got connection");
    }
    catch (NamingException ex)
    {
      System.err.println("failed to obtain JNDI context");
      throw new HalvorException("failed to obtain JNDI context", ex);
    }
    catch (SQLException ex)
    {
      System.err.println("failed to open database connection");
      throw new HalvorException("failed to open database connection", ex);
    }


The output from the above is:

instantiating database connection
getting InitialContext
got InitialContext
enumeration name = insuranceAdminTest: org.apache.naming.ResourceRef
getting JDBC context
got jdbcContext
looking up insuranceAdminTest
failed to obtain JNDI context


The server.xml snippet is:

<Resource name="jdbc/insuranceAdminTest" auth="CONTAINER"
                      type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/insuranceAdminTest">
    <parameter><name>user</name><value>halvor</value></parameter>
    <parameter><name>password</name><value>halvor</value></parameter>

<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value
></parameter>

<parameter><name>driverName</name><value>jdbc:mysql:///InsuranceAdminTest</v
alue></parameter>
  </ResourceParams>

the web.xml snippet is:

  <resource-ref>
    <res-ref-name>jdbc/insuranceAdminTest</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>



What I dont understand is that the line that prints "enumeration name = "
find the insuranceAdminTest binding, but the subsequent lookup on the
jdbcContext Context fails...




Does anyone know what is wrong?


Many thanks - Adam Lipscombe



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to