Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Exclamation Unanswered: JNDI - NameNotFoundException

    Hello all,

    I have been using Tomcat for a while but have just started to leverage JNDI as a method of utilizing Tomcat 4.1's dbconnection pooling. I have set up my server.xml with the following:

    ...
    <Context path="/MyApp" docBase="MyApp" debug="5" reloadable="true" crossContext="true">
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="MyApp." suffix=".txt"
    timestamp="true"/>

    <Resource name="jdbc/MyApp"
    auth="Container"
    type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/myDB">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFact ory</value>
    </parameter>

    <!-- Maximum number of dB connections in pool. Make sure you
    configure your mysqld max_connections large enough to handle
    all of your db connections. Set to 0 for no limit.
    -->
    <parameter>
    <name>maxActive</name>
    <value>100</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
    Set to 0 for no limit.
    -->
    <parameter>
    <name>maxIdle</name>
    <value>30</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
    in ms, in this example 10 seconds. An Exception is thrown if
    this timeout is exceeded. Set to -1 to wait indefinitely.
    -->
    <parameter>
    <name>maxWait</name>
    <value>10000</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections -->
    <parameter>
    <name>username</name>
    <value>myDB_user</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>abc123</value>
    </parameter>

    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
    </parameter>

    <!-- The JDBC connection url for connecting to your MySQL dB.
    The autoReconnect=true argument to the url makes sure that the
    mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
    connection. mysqld by default closes idle connections after 8 hours.
    -->
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/myDB?autoReconnect=true</value>
    </parameter>
    </ResourceParams>

    </Context>
    ...


    But when I call any servlet that relys on this data source (to get a connection object) I get the following error from Tomcat:

    ...
    javax.naming.NameNotFoundException: Name myDB is not bound in this Context
    ...

    Here is an example of how I am calling the JNDI:

    ...
    Context ctx = new InitialContext();
    DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/myDB");

    Connection con = ds.getConnection();
    ...


    Any help would be great
    Thanks

  2. #2
    Join Date
    Dec 2003
    Location
    San Diego
    Posts
    1

    Re: JNDI - NameNotFoundException

    Hi,

    I am having the same problem, although I get naming exceptions complaining about the comp name, as in java:comp/env/jdbc/mydb.

    I am using Linux with Tomcat and PostgreSQL.

    Did you find the solutioin? I wish I could help you but I am perplexed as my setup doesn't seem to behave as the documentation says.

    Thanks
    Tony

    Originally posted by LordKrispy
    Hello all,

    I have been using Tomcat for a while but have just started to leverage JNDI as a method of utilizing Tomcat 4.1's dbconnection pooling. I have set up my server.xml with the following:

    ...
    <Context path="/MyApp" docBase="MyApp" debug="5" reloadable="true" crossContext="true">
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="MyApp." suffix=".txt"
    timestamp="true"/>

    <Resource name="jdbc/MyApp"
    auth="Container"
    type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/myDB">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFact ory</value>
    </parameter>

    <!-- Maximum number of dB connections in pool. Make sure you
    configure your mysqld max_connections large enough to handle
    all of your db connections. Set to 0 for no limit.
    -->
    <parameter>
    <name>maxActive</name>
    <value>100</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
    Set to 0 for no limit.
    -->
    <parameter>
    <name>maxIdle</name>
    <value>30</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
    in ms, in this example 10 seconds. An Exception is thrown if
    this timeout is exceeded. Set to -1 to wait indefinitely.
    -->
    <parameter>
    <name>maxWait</name>
    <value>10000</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections -->
    <parameter>
    <name>username</name>
    <value>myDB_user</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>abc123</value>
    </parameter>

    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
    </parameter>

    <!-- The JDBC connection url for connecting to your MySQL dB.
    The autoReconnect=true argument to the url makes sure that the
    mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
    connection. mysqld by default closes idle connections after 8 hours.
    -->
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/myDB?autoReconnect=true</value>
    </parameter>
    </ResourceParams>

    </Context>
    ...


    But when I call any servlet that relys on this data source (to get a connection object) I get the following error from Tomcat:

    ...
    javax.naming.NameNotFoundException: Name myDB is not bound in this Context
    ...

    Here is an example of how I am calling the JNDI:

    ...
    Context ctx = new InitialContext();
    DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/myDB");

    Connection con = ds.getConnection();
    ...


    Any help would be great
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •