You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ohaya <oh...@cox.net> on 2004/08/07 17:24:48 UTC
Newbie - JDBC problem "Name is not bound in this context"
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. I've
been using the bridge driver from standalone Java applications, so I
think 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.
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:
<%@ 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 certrequest_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.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.27
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Newbie - JDBC problem "Name is not bound in this context"
Posted by ohaya <oh...@cox.net>.
> I'm not a JNDI expert but you can try this:
>
> Context ic = new InitialContext();
> Context ctx = (Context) ic.lookup("java:comp/env");
> DataSource ds = (DataSource) ic.lookup("jdbc/jimnew");
>
Hi Dennis,
I've been wrestling with this problem for most of today, and at this
point, I don't think the problem is with the code, but rather, I think
it's some kind of problem with configuration. What it looks like is
that Tomcat, for some reason, doesn't think that there is a resource
called 'jdbc/jimnew', even though 'jdbc/jimnew' appears to exist in
GlobalNamingResources in server.xml.
After working on this for hours, I'm a bit confused about this, as my
impression was that if a resource was defined in GlobalNamingResources,
then any application would be able to access that resource.
I kind of "cheated" a bit with my small test page, and maybe that's why
things aren't working.
When Tomcat installed, it had a bunch of demo applications at
http://myhost/jsp-examples. Just for this (I thought) quick test, I
created a single JSP file, test.jsp in the jsp-examples directory,
because I didn't want to go through all of the things to set up a new
"application" in Tomcat, and I thought that my test.jsp would be
automatically able to "see" the resources in GlobalNamingResources.
Well, I'm either doing something wrong, or my assumption was wrong,
because I keep getting that error ("jdbc not bound in this context"),
and I can't find any way around it. I've tried adding the resource-ref,
res-ref-name, res-type, and res-auth to the web.xml in the
jsp-examples\WEB-INF directory, but even that didn't do the trick.
At this point, I'm kind of stuck, and I'm hoping that someone on this
list can tell me how I might be able to make this resource visible to my
test.jsp.
If I can't figure that out, I'm probably going to just try doing the
JDBC stuff directly, without JNDI, etc...
Thanks for trying...
Jim
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Newbie - JDBC problem "Name is not bound in this context"
Posted by Dennis Dai <dd...@ddai.net>.
On 8/7/2004 8:24 AM, ohaya wrote:
> 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. I've
> been using the bridge driver from standalone Java applications, so I
> think 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.
>
> I was wondering if anyone could tell me what I'm doing wrong?
>
[snipped]
>
>
> and here's my JSP:
...
> Context ic = new InitialContext();
> DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/jimnew");
I'm not a JNDI expert but you can try this:
Context ic = new InitialContext();
Context ctx = (Context) ic.lookup("java:comp/env");
DataSource ds = (DataSource) ic.lookup("jdbc/jimnew");
--
Dennis Dai
ddai-ml@ddai.net
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org