AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with JSP and JDBC

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
ohaya
Guest





PostPosted: Sat Aug 07, 2004 6:07 pm    Post subject: Problem with JSP and JDBC Reply with quote



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) %>
<%
}
} 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.
Back to top
Murray
Guest





PostPosted: Sun Aug 08, 2004 1:07 am    Post subject: Re: Problem with JSP and JDBC Reply with quote




"ohaya" <ohaya (AT) cox (DOT) net> wrote

....
Quote:
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>




Back to top
ohaya
Guest





PostPosted: Sun Aug 08, 2004 1:51 am    Post subject: Re: Problem with JSP and JDBC Reply with quote





Murray wrote:
Quote:

"ohaya" <ohaya (AT) cox (DOT) net> wrote

...
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 /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]confCatalinalocalhost 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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.