JNDI NamingException


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: JNDI NamingException

  1. #1
    Join Date
    Mar 2005
    Posts
    110

    JNDI NamingException

    Hi,
    I'm trying to connect to an SQL Server database using JNDI lookup from Tomcat 5.5.9 and eclipse 3.1 and got an exception I can't figure out.

    The error message reads: Name BookDb is not bound in this Context

    I use "http://localhost:8080/admin" to config Data Source

    My server.xml looks like:
    ...
    <GlobalNamingResources>
    <GlobalNamingResources>
    <Environment
    name="simpleValue"
    type="java.lang.Integer"
    value="30"/>
    <Resource
    auth="Container"
    description="User database that can be updated and saved"
    name="UserDatabase"
    type="org.apache.catalina.UserDatabase"
    pathname="conf/tomcat-users.xml"
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
    name="jdbc/BookDB"
    type="javax.sql.DataSource"
    driverClassName="net.sourceforge.jtds.jdbc.Driver"
    password="sa"
    maxIdle="2"
    maxWait="5000"
    username="sa"
    url="jdbc:jtds:sqlserver://10.0.0.5:1433/;DatabaseName=DEMODATA"
    maxActive="4"/>
    </GlobalNamingResources>


    My web.xml looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>JNDITest</display-name>
    <servlet>
    <display-name>TestDataSource</display-name>
    <servlet-name>TestDataSource</servlet-name>
    <servlet-class>TestDataSource</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>TestDataSource</servlet-name>
    <url-pattern>/TestDataSource</url-pattern>
    </servlet-mapping>

    <resource-ref>
    <res-ref-name>jdbc/BookDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    </web-app>


    Help!
    Does anyone know how to fix this problem?
    thanks

  2. #2
    Join Date
    Aug 2004
    Posts
    46
    Can you post the code for your JNDI lookup?

  3. #3
    Join Date
    Mar 2005
    Posts
    110
    here is my JNDI lookup , it is from the BOOKSTORE sample of J2eetutorial14. I just change database from Pointbase to SQL Server

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

Similar Threads

  1. Replies: 0
    Last Post: 04-26-2002, 08:01 AM
  2. LDAP JNDI Connection sharing?
    By Marc Boorshtein in forum Java
    Replies: 0
    Last Post: 08-13-2001, 11:27 AM
  3. Sample of JNDI and RMI with WebLogic
    By Alexia in forum Java
    Replies: 1
    Last Post: 05-11-2000, 05:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center