Hi,
I just got Tomcat 5.0.27 installed (with Apache 2.0.50), and am trying
to get a simple JDBC JSP working. The JSP is called 'test.jsp'.
I have the JDBC-ODBC bridge installed and am going through that and the
Oracle ODBC driver to get to an Oracle database. I've been using the
bridge driver via ODBC for some other standalone (not web) Java
applications and that works ok, so I think that that is working ok, but
even with a really simple JSP, I'm getting an "Name jdbc is not bound in
this context" error.
I'm including my server.xml, test.jsp, and the error details below.
Basically, what I've done is to use the Tomcat administration web
application to create the DataSource, which looks like it populated the
server.xml (see below). I then try to access the test.jsp, and am
getting that "not bound" error.
I've checked the server.xml and the entries look ok (i.e., they have the
matching "jdbc/jimnew" name as shown below).
I was wondering if anyone could tell me what I'm doing wrong?
Thanks,
Jim
Here's my server.xml:
<?xml version='1.0' encoding='utf-8'?>
<Server>
<Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<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"/>
<Resource name="jdbc/jimnew" type="javax.sql.DataSource"/>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<ResourceParams name="jdbc/jimnew">
<parameter>
<name>validationQuery</name>
<value></value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:odbc:PROD</value>
</parameter>
<parameter>
<name>password</name>
<value>password</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>sun.jdbc.odbc.JdbcOdbcDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>jim</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<Service name="Catalina">
<Connector acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true" port="9090" redirectPort="8443"
maxSpareThreads="75" maxThreads="150" minSpareThreads="25">
</Connector>
<Connector enableLookups="true" port="8009" protocol="AJP/1.3"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
redirectPort="8443">
</Connector>
<Engine defaultHost="localhost" name="Catalina">
<Host appBase="webapps" name="localhost">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_log." suffix=".txt" timestamp="true"/>
</Host>
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>
</Service>
</Server>
and here's my JSP (test.jsp):
<%@ page import='java.sql.*, javax.sql.*, javax.naming.*' %>
<%
Context ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/jimnew");
Connection conn = ds.getConnection();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from test_db");
%><h2>Brooms:</h2><%
while (rs.next()) { %>
<%= rs.getString(1) %> <%= rs.getString(2) %><br><%
}
} finally {
conn.close();
}
%>
The exact error I'm getting is:
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
javax.servlet.ServletException: Name jdbc is not bound in this Context
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.test_jsp._jspService(test_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.naming.NameNotFoundException: Name jdbc is not bound in this
Context
org.apache.naming.NamingContext.lookup(NamingContext.java:768)
org.apache.naming.NamingContext.lookup(NamingContext.java:138)
org.apache.naming.NamingContext.lookup(NamingContext.java:779)
org.apache.naming.NamingContext.lookup(NamingContext.java:138)
org.apache.naming.NamingContext.lookup(NamingContext.java:779)
org.apache.naming.NamingContext.lookup(NamingContext.java:151)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
javax.naming.InitialContext.lookup(InitialContext.java:347)
org.apache.jsp.test_jsp._jspService(test_jsp.java:49)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.27 logs.
Murray - 08 Aug 2004 02:07 GMT
...
> Basically, what I've done is to use the Tomcat administration web
> application to create the DataSource, which looks like it populated the
> server.xml (see below). I then try to access the test.jsp, and am
> getting that "not bound" error.
You need to "mention" the datasource in your web.xml as well
<resource-ref>
<description></description>
<res-ref-name>jdbc/jimnew</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref
ohaya - 08 Aug 2004 02:51 GMT
> ...
> > Basically, what I've done is to use the Tomcat administration web
[quoted text clipped - 10 lines]
> <res-auth>Container</res-auth>
> </resource-ref>
Murray,
Thanks. I did that, but even with that, it wasn't working.
I had subscribed to the Tomcat mailing list, and someone suggested
adding a ResourceLink, but I couldn't figure out where to put it,
because the Server.xml that was installed didn't have a Context. While
digging around, I found that buried deep in the directories installed,
there was a [TOMCAT HOME]\conf\Catalina\localhost directory where there
was one .XML file for each of the installed webapps/directories, and
each of these .XML files had the Context for the webapp.
So, I added a ResourceLink to the jsp-examples.xml file, restarted
Tomcat, and everything started working!!
Thanks again,
Jim