tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David De Graff" <tom...@awarehouse.com>
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 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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message