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(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.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(JspCompilationContext.java:556) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.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-nametestdb/display-name description db test site /description resource-ref descriptionTomcat DBCP/description res-ref-namejdbc/testdb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app conf/Catalina/localhost/testdb.xml: ?xml version=1.0 encoding=UTF-8? Context path=/Search docBase=Search debug=1crossContext=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= password= 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]
Re: Tomcat 5.5.9: NamingException cannot be resolved or is not a type - JNDI, MySQL
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-nametestdb/display-name description db test site /description resource-ref descriptionTomcat DBCP/description res-ref-namejdbc/testdb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app conf/Catalina/localhost/testdb.xml: ?xml version=1.0 encoding=UTF-8? Context path=/Search docBase=Search debug=1crossContext=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= password= 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]
Re: Tomcat 5.5.9: NamingException cannot be resolved or is not a type - JNDI, MySQL
Great! Thanks Torsten. Added javax.naming Now new problem: NamingException: javax.naming.NamingException: Could not create resource factory, ClassNotFoundException:org.apache.commons.dbcp.BasicDataSourceFactory This exposed several other pitfalls. Tomcat distribution did not come with the apache commons jars: collections, dbcp, pool. Installed them in common/lib and all is well. Thanks tons. Greg. Torsten Römer wrote: Greg Brownell schrieb: 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 % You are missing javax.naming.NamingException (or do javax.naming.*) Torsten 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-nametestdb/display-name description db test site /description resource-ref descriptionTomcat DBCP/description res-ref-namejdbc/testdb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app conf/Catalina/localhost/testdb.xml: ?xml version=1.0 encoding=UTF-8? Context path=/Search docBase=Search debug=1crossContext=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= password= 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