Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

install DBCP and mm.mysql 2.0.14 (JDBC Driver) and test app, get class compile error.

Wayne Bragg

2007-03-05

Replies:

Sorry about the previous premature post.....
This is the full question/problem....

I am trying to install DBCP and mm.mysql 2.0.14 (JDBC Driver) and a test app to see if it works.
I'm not sure I have all the correct steps and configuration, in other words I don't know what I am doing.. Here is what I know and my setup for this test example that I keep getting a class compile error on.

You can probably tell I only have HALF a clue at best? Any ideas what's wrong?

This is the error reported by browser -

type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to a type
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to a type
org.apache.jasper.servlet.JspServletWrapper.handleJspException (JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:264)
javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to a type
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to 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:414)
org.apache.jasper.compiler.Compiler.compile (Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile (Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile (Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile (JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:264)
javax.servlet.http.HttpServlet.service (HttpServlet.java:802)

This is the Tomcat log -

Mar 5, 2007 12:13:30 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to a type
An error occurred at line: 7 in the jsp file: /test.jsp
Generated servlet error:
foo.DBTest cannot be resolved to a type
at org.apache.jasper.compiler.DefaultErrorHandler.javacError (DefaultErrorHandler.java:84)
at org.apache.jasper.compiler.ErrorDispatcher.javacError (ErrorDispatcher.java:328)
at org.apache.jasper.compiler.JDTCompiler.generateClass (JDTCompiler.java:414)
at org.apache.jasper.compiler.Compiler.compile (Compiler.java:297)
at org.apache.jasper.compiler.Compiler.compile (Compiler.java:276)
at org.apache.jasper.compiler.Compiler.compile (Compiler.java:264)
at org.apache.jasper.JspCompilationContext.compile (JspCompilationContext.java:563)
at org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:305)
at org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service (JspServlet.java:264)
at javax.servlet.http.HttpServlet.service (HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process (Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket (PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt (LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)

This is how I setup and config for the DBCP and mm.mysql 2.0.14 (JDBC Driver)

Added to \www\tomcat5\common\lib
  commons-pool-1.3.jar
  commons-collections-3.2.jar
  commons-dbcp-1.2.1.jar

Added to \www\webapps\DBTest\WEB-INF\lib
  mm.mysql-2.0.14-bin.jar

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="WEB-INF/java">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="WEB-INF/lib/mm.mysql-2.0.14-bin.jar">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.gjt.mm.mysql.Driver">
<attributes>
</attributes>
</classpathentry>
<classpathentry kind="output" path="WEB-INF/classes"/>
</classpath>

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>chat-demo-war</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
 <name>org.eclipse.jdt.core.javabuilder</name>
 <arguments>
 </arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

\DBTest\WEB-INF\web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App</description>
<resource-ref>
   <description>DB Connection</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>

Added to server.xml

<Context path="/DBTest" docBase="DBTest"
 debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost_DBTest_log." suffix=".txt"
    timestamp="true"/>
<Resource name="jdbc/TestDB"
    auth="Container"
    type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/TestDB">
  <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
  </parameter>
  <parameter>
    <name>maxActive</name>
    <value>100</value>
  </parameter>
  <parameter>
    <name>maxIdle</name>
    <value>30</value>
  </parameter>
  <parameter>
    <name>maxWait</name>
    <value>10000</value>
  </parameter>
  <parameter>
    <name>username</name>
    <value>javauser</value>
  </parameter>
  <parameter>
   <name>password</name>
   <value>javadude</value>
  </parameter>
  <parameter>
   <name>driverClassName</name>
   <value>org.gjt.mm.mysql.Driver</value>
  </parameter>
  <parameter>
   <name>url</name>
   <value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
  </parameter>
The example I was following wasn't clear about if these next three went here or not
<parameter>
   <name>removeAbandoned</name>
   <value>true</value>
  </parameter>
  <parameter>
   <name>removeAbandonedTimeout</name>
   <value>60</value>
  </parameter>
  <parameter>
   <name>logAbandoned</name>
   <value>true</value>
  </parameter>
</ResourceParams>
</Context>

The class I can't get to compile

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

String foo = "Not Connected";
int bar = -1;
 
public void init() {
  try{
   Context ctx = new InitialContext();
   if(ctx == null )
      throw new Exception("Boom - No Context");

   DataSource ds =
       (DataSource)ctx.lookup(
         "java:comp/env/jdbc/TestDB");

   if (ds != null) {
    Connection conn = ds.getConnection();
       
    if(conn != null) {
       foo = "Got Connection "+conn.toString();
       Statement stmt = conn.createStatement();
       ResultSet rst =
          stmt.executeQuery(
           "select id, foo, bar from testdata");
       if(rst.next()) {
         foo=rst.getString(2);
         bar=rst.getInt(3);
       }
       conn.close();
    }
   }
  }catch(Exception e) {
   e.printStackTrace();
  }
}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}

The test application

<html>
<head>
  <title>DB Test</title>
</head>
<body>

<%
  foo.DBTest tst = new foo.DBTest();
  tst.init();
%>

<h2>Results</h2>
  Foo <%= tst.getFoo() %><br/>
  Bar <%= tst.getBar() %>

</body>
</html>
©2008 junlu.com - Jax Systems, LLC, U.S.A.