tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohaya <oh...@cox.net>
Subject Newbie - JDBC problem "Name is not bound in this context"
Date Sat, 07 Aug 2004 15:24:48 GMT
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


Mime
View raw message