tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David De Graff" <>
Subject Problem with JNDI Datasource HOW-TO MySQL Example
Date Fri, 31 Oct 2003 08:25:07 GMT
I'm new to Java but have installed Tomcat a couple of times, and am now
trying to configure a JNDI datasource (to use with the OpenReports database
reporting package - see for info on

Before configuring a datasource for db reporting, I'm trying to set up the
test datasource described on the JNDI Datasource HOW-TO at
to.html, under the section "MySQL DBCP Example".

I've edited the conf/server.xml and webapps/DBTest/WEB-INF/web.xml files as
indicated in the HOW-TO. When deploying the code in this sample webapp with
Tomcat 4.1.27, I either get a 404 or an error that includes the following:

" An error occurred at line: 6 in the jsp file: /test.jsp

Generated servlet error:
    [javac] Compiling 1 source file

/home/ddegraff/packages/openreports-tomcat/work/Standalone/localhost/DBTest/ package foo does not exist
    foo.DBTest tst = new foo.DBTest();"

The above error occurs if the jsp file and class file are in the
$CATALINA_HOME/webapps/DBTest directory together. If I put the compiled
class file (DBTest.class) in webapps/DBTest/WEB-INF/classes, I get a 404
when trying to access the jsp.

The jsp file and class file source is copied below. Any insight would be
much appreciated.


Dave De Graff

JSP file text:
    <title>DB Test</title>

    foo.DBTest tst = new foo.DBTest();

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

---------------------------------- file text:
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(
      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( {               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;}}

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message