Excellent! That worked on the first try, and it turns out that the test JNDI
datasource also works.

It's strange that the need to put class files in a directory of their
package name isn't mentioned in the O'Reilly Tomcat book (diagram on p. 71
shows class file in the WEB-INF/classes directory). Or maybe only some class
files need to be in a package subdirectory?

In any case, thanks much for the help!

Dave

----- Original Message -----
From: "Antony Paul" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Friday, October 31, 2003 12:42 AM
Subject: Re: Problem with JNDI Datasource HOW-TO MySQL Example


> simple suggestion.
> put the class file in webapps/DBTest/WEB-INF/classes/foo.
>
> Antony.
>
> ---- Original Message -----
> From: "David De Graff" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, October 31, 2003 1:55 PM
> Subject: Problem with JNDI Datasource HOW-TO MySQL Example
>
>
> > 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 http://sourceforge.net/projects/oreports for
info
> on
> > that).
> >
> > Before configuring a datasource for db reporting, I'm trying to set up
the
> > test datasource described on the JNDI Datasource HOW-TO at
> >
>
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-how
> > 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/
> > test_jsp.java:48: 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.
> >
> > Best,
> >
> > Dave De Graff
> >
> > JSP file text:
> > <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>
> > ----------------------------------
> > DBTest.java 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(
> > "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;}}
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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