I have.  Here is what I have at top of jsp:

<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="java.io.File" %>

Greg.

Arnaud HERITIER wrote:

You must import the classes you use in your JSP :

<%@ page import="{package.class | package.*}, ..." ...

Arnaud


-----Message d'origine-----
De : Greg Brownell [mailto:[EMAIL PROTECTED] Envoyé : mercredi 8 juin 2005 21:34
À : tomcat-user@jakarta.apache.org
Objet : Tomcat 5.5.9: NamingException cannot be resolved or is not a type - JNDI, MySQL

I get the error below when trying to compile/execute a jsp that wants to connect to a MySQL db named

testdb.  Here's the code snippet from testdb.jsp:

        InitialContext initCtx = null;
        DataSource ds = null;
        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
                initCtx = new InitialContext();

ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/testdb");
                conn = ds.getConnection();
                
                stmt = conn.createStatement();
                rset = stmt.executeQuery("select * from subscriber");

It fails on the lookup with:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 52 in the jsp file: /testdb.jsp Generated servlet error:
NamingException cannot be resolved or is not a type


        
org.apache.jasper.compiler.DefaultErrorHandler.javacError(Defa
ultErrorHandler.java:84)
        
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDis
patcher.java:328)
        
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompil
er.java:397)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
        
org.apache.jasper.JspCompilationContext.compile(JspCompilation
Context.java:556)
        
org.apache.jasper.servlet.JspServletWrapper.service(JspServlet
Wrapper.java:293)
        
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet
.java:291)
        
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

I am using MySQL 4.1.12a (Windows nt), Connector/J v 3.1.8 Connector/j stuff moved to common/lib

Tomcat: under webapps, app name testdb.
testdb/WEB-INF/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">

<display-name>testdb</display-name>
  <description>
    db test site
  </description>

<resource-ref>
        <description>Tomcat DBCP</description>
        <res-ref-name>jdbc/testdb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>
</web-app>

conf/Catalina/localhost/testdb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context
 path="/Search"   docBase="Search"
 debug="1"    crossContext="true"
  reloadable="true">
<ResourceLink name="jdbc/testdb" type="javax.sql.DataSource" global="jdbc/testdb"/> </Context>

conf/server.xml:
<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"
    pathname="conf/tomcat-users.xml"
    factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
  name="jdbc/testdb"
  auth="Container"
  type="javax.sql.DataSource"
  factory="org.apache.commons.dbcp.BasicDataSourceFactory"
  username="xxxx"
  password="yyyy"
  removeAbandonedTimeout="60"
  maxActive="4"
  maxIdle="2"
  removeAbandoned="true"
  driverClassName="com.mysql.jdbc.Driver"
  url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
</GlobalNamingResources>

Any ideas why this doesn't work?

By the way, I've tried moving the Resource lines in server.xml to testdb.xml (the context file) and replaced the resource-link. Same error.

Thanks in advance.

Greg.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to