Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Tomcat 5.5.9 - Name jdbc is not bound in this Context

843859Oct 12 2005 — edited Nov 4 2005
Hi,

I'm moving an J2EE web application from an Oracle 10G AS to an Apache
Tomcat server (V5.5.9) the web application works fine on the Oracle app server but on the Tomcat server I receive the following error when the application makes a database (Oracle 10G) call. the application context is "tl"


--------------------------------------------------------------------------------
HTTP Status 500 -
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

uk.co.troutlure.dao.DataAccessErrorException: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
uk.co.troutlure.dao.BaseDAO.<init>(BaseDAO.java:40)
uk.co.troutlure.dao.SearchDAO.<init>(SearchDAO.java:24)
uk.co.troutlure.common.searchActionClass.execute(searchActionClass.java:148)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


--------------------------------------------------------------------------------
Apache Tomcat/5.5.9
--------------------------------------------------------------------------------


My Server.xml is in the "<Apache Root>\Tomcat 5.5\conf" directory and is as follows:

--------------------------------------------------------------------------------
Server.xml
--------------------------------------------------------------------------------
<!-- Global JNDI resources -->
<GlobalNamingResources>

<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>

<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />

<!-- DataSource definition for TL_COS Application-->
<Context path="/tl" docBase="tl" debug="1" reloadable="true" useNaming="true">
<Resource name="jdbc/TL_USER_DBConnectionDS" auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TL_USER_DBConnectionDS">
<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:@169.254.225.173:1521:orcl</value>
</parameter>
<parameter>
<name>username</name>
<value>TLDATA</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>40</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>

</GlobalNamingResources>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------



My web.xml in the "<Tomcat Root\Apache Software Foundation\Tomcat 5.5\conf\" directory is as follows:
--------------------------------------------------------------------------------
Web.xml
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
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"
version="2.4">

<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/TL_USER_DBConnectionDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
...

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

There is also a web.xml within the application under the WEB-INF directory
--------------------------------------------------------------------------------
Web.xml
--------------------------------------------------------------------------------
<?xml version = '1.0' encoding = 'windows-1252'?>
<!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>
<description>web.xml file for TL COS Application</description>
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/cd_managerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/WEB-INF/taglib/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/taglib/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/taglib/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/taglib/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</web-app>

--------------------------------------------------------------------------------

I make the database calls from a data access object which is as follows:
--------------------------------------------------------------------------------
BaseDAO.java
--------------------------------------------------------------------------------
Context ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(
"jdbc/TL_USER_DBConnectionDS");
conn = ds.getConnection();
} catch (SQLException exception) {
throw new DataAccessErrorException(exception);
} catch (NamingException exception) {
throw new DataAccessErrorException(exception);
}


--------------------------------------------------------------------------------

I have added the ojdbc14.jar file to the "Tomcat Root\\Tomcat 5.5\common\lib" directory.

Do I need to set JAVA_HOME or CATALINA_HOME???? if so what to??? or is the problem relating to something different??

Any ideas where I'm going wrong would be a great help.

Many Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2005
Added on Oct 12 2005
15 comments
1,273 views