Cindy and list,

well I am almost there but I am confused about the resource entry...

I am using Tomcat 4.1.3, and usinging all the commons stuff that gets 
bundled with that binary distribution, because I was told on the list that 
it works.

my server.xml file has the following entry...

<!--  the data source added by Clay-->
<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>30000</value></parameter>
      <parameter><name>maxWait</name><value>100</value></parameter>
      <parameter><name>username</name><value>tomcat</value></parameter>
      <parameter><name>password</name><value>password</value></parameter>
     <parameter>
       <name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value>
     </parameter>
    <parameter>
      <name>url</name><value>jdbc:mysql://localhost:3306/test</value>
    </parameter>
  </ResourceParams>
</Context>

this is confusing because first of all I read on the list that needed to 
create a directory under my webapps called /DBTest (for my example) I don't 
really see how you are doing you're path to jdbc/Support, did you create a 
directory? This is what was causing my initial failure (a detail not in the 
DBCP guide), secondly I was watching the DBTest logs at startup and it 
complained that there was no web.xml or WEB-INF dir for the context, do you 
have a web.xml file that you put in this directory?

In my web.xml for my application ($CATALINA_HOME/webapps/test/WEB-INF/we  
b.xml) I have added:

  <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>

so instead of doing exactly what you are doing to test the datasource in a 
servlet, I am calling it with and action and then putting the output to a 
page bean, (the STRUTS way) but its identical to calling a printstream for 
a servlet, this is the code....

Context initCtx, envCtx;
DataSource ds;

try {
  message = message+"AppController: setting initial context\n";
  initCtx = (Context) new InitialContext();

  message = message+"AppController: getting the context environment\n";
  envCtx = (Context) initCtx.lookup("java:comp/env");

  message = message+"AppController: setting up the DataSource\n";
  ds = (DataSource) envCtx.lookup("jdbc/TestDB");
  if (ds != null ) {
    message = message+"AppController: DataSource is ready\n";
    //ds.setLogWriter(new PrintWriter(System.out));

               Connection conn = ds.getConnection();

                if(conn != null)  {
                    message = "Got Connection "+conn.toString()+"\n";
                    Statement stmt = conn.createStatement();
                    ResultSet rst = stmt.executeQuery("select fname, lname, 
email from users");
                    if(rst.next()) {
                        fname=rst.getString(1);
                        lname=rst.getString(2);
                        email=rst.getString(3);
                        message=message+fname+" "+lname+" "+email+"\n";
                    }
                    conn.close();
                }
  }
  else {
    message = message+"AppController: DataSource is null\n";
  }
}
catch (Exception e) {
  message = message+"Exception - context: " + e + "\n" + 
e.getMessage()+"\n";
}

here is what i get back....

message:
AppController: setting initial context
AppController: getting the context environment
AppController: setting up the DataSource
AppController: DataSource is ready
Exception - context: java.sql.SQLException: Cannot load JDBC driver class 
'null' Cannot load JDBC driver class 'null'

and when I look at the log for catalina.out...

java.sql.SQLException: Cannot load JDBC driver class 'null'
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(Unknown 
Source)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(Unknown 
Source)
        at com.noi.webapp.test.action.RegisterAction.perform(Unknown 
Source)
        at 
org.apache.struts.action.ActionServlet.processActionPerform(ActionServle
        at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)

I know that the mysql jar is in there....

[clay@meis jakarta-tomcat-4.1.3]$ ls common/lib/mm*.jar
common/lib/mm.mysql-2.0.14-bin.jar



-----Original Message-----
From:   Cindy Ballreich [SMTP:[EMAIL PROTECTED]]
Sent:   Tuesday, July 09, 2002 10:06 AM
To:     [EMAIL PROTECTED]
Subject:        Re: going crazy with DBCP


Hi Clay,

Let's see if I can give you a hand with this. Let me ask a couple of 
questions first. It sounds like you're working from RPMs, is this true? If 
so, that may have something to do with your problems.

I'm using Tomcat 4.0.3 (although 4.0.4 will probably also work fine and I 
plan on upgrading soon).

I'm using jdk 1.3.1_2 from Sun.

On my system I have all the Java stuff (including Tomcat) installed under 
/usr/local/java. I've installed all the Tomcat stuff from the binary 
(non-RPM) distributions inside this directory. All of my environment 
variables (JAVA_HOME, CATALINA_HOME, etc.) are set in /etc/profile. Just to 
make things easier, I've made symbolic links to the latest version of 
Tomcat and the latest jdk so I don't have to change the environment 
variables whenever I upgrade, just the links...
jdk -> /usr/local/java/jdk1.3.1_02/
catalina -> /usr/local/java/jakarta-tomcat-4.0.3/

I have an init.d script that I've written to start and stop everything. 
(Let me know if you need a copy.)

I downloaded Collections 2.0 from here... (watch for line wrapping) 
http://jakarta.apache.org/builds/jakarta-commons/release/commons-collect  
ions/v2.0/

I downloaded Pool 1.0 from here... 
http://jakarta.apache.org/builds/jakarta-commons/release/commons-pool/v1.0/

I downloaded the latest nightly build of DBCP from here... 
http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-dbcp/

I've put all of these jars in $CATALINA_HOME/common/lib/

Here's the Resource stuff from inside of my application's context section 
in $CATALINA_HOME/conf/server.xml...
<Resource name="jdbc/Support" auth="Container" 
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/Support">
  <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>30000</value>
  </parameter>
  <parameter>
    <name>maxWait</name><value>100</value>
  </parameter>
  <parameter>
    <name>username</name><value>devusername</value>
  </parameter>
  <parameter>
    <name>password</name><value>devuserpwd</value>
  </parameter>
  <parameter>
    <name>driverClassName</name>
    <value>org.gjt.mm.mysql.Driver</value>
  </parameter>
  <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/devdb</value>
  </parameter>
</ResourceParams>

Here's the resource reference from the bottom of my application's 
WEB-INF/web.xml...
<resource-ref>
  <description>Resource reference to a factory for 
     javax.sql.Datasource</description>
  <res-ref-name>jdbc/devdb</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

Finally, from my servlet:
Here's the variables...
  private Context initCtx;
  private Context envCtx;
  private DataSource ds;

And here's the important part from the init() method...
try {
  System.out.println("AppController: setting initial context");
  initCtx = (Context) new InitialContext();

  System.out.println("AppController: getting the context environment");
  envCtx = (Context) initCtx.lookup("java:comp/env");

  System.out.println("AppController: setting up the DataSource");
  ds = (DataSource) envCtx.lookup("jdbc/devdb");
  if (ds != null ) {
    System.out.println("AppController: DataSource is ready");
    ds.setLogWriter(new PrintWriter(System.out));
  }
  else {
    System.out.println("AppController: DataSource is null");
  }
}
catch (Exception e) {
  System.out.println("Exception - context: " + e + "\n" + e.getMessage());
}

This is all more or less what's in the link you've been using. I think 
there are a couple of modifications for my situation that may work for you. 

Please let me know if this is helpful or if you have any questions about 
what I've written.

Cindy


At 04:36 PM 7/8/02 -0700, Clay Graham wrote:
>I will pay someone to help me at this point, I am not rich but I know when 
>to admit when need help. I am basically at the end of my rope trying to 
get
>dbcp to work, I have been over
>
>http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2
>
>about one hundred times, basically it's impossible to get the exact
>configuration that he speaks of, like some of the commons stuff I couldn't 
>find those versions, anyway it would really suprise me if those EXACT
>versions are the only ones that work.
>
>I tried to install the RPM 4.0.4 version of tomcat and the webapps, but I
>could not get the manager to work, so I went back to 4.0.2. Is there such 
a
>difference between 4.0.2 and to point versions that it causes this stuff 
to
>fail? Is the only way to get DBCP to work is to actually build tomcat from 
>source? Anyway I have done the best I can and spent two days configuring,
>this where I am at:
>
>tomcat 4.0.2 full
>mysql 4.0.1-2
>
>mm.mysql-2.0.14-bin.jar in $TOMCAT_HOME/common/lib
>
>commons-collections-2.0 - commons-collections.jar in
>$TOMCAT_HOME/common/lib
>commons-dbcp-20020707.tar.gz - commons-dbcp.jar in $TOMCAT_HOME/common/lib
>commons-pool-20020707.tar.gz - commons-pool.jar in $TOMCAT_HOME/common/lib
>
>added to server.xml
>
><!--  the data source added by Clay-->
><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>30000</value></parameter>
>      <parameter><name>maxWait</name><value>100</value></parameter>
>      <parameter><name>username</name><value>tomcat</value></parameter>
>      <parameter><name>password</name><value>password</value></parameter>
>     <parameter>
>       <name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value>
>     </parameter>
>    <parameter>
>      <name>url</name><value>jdbc:mysql://localhost:3306/test</value>
>    </parameter>
>  </ResourceParams>
></Context>
>
>when tomcat is started i get the following log errors:
>
>2002-07-08 16:14:38 StandardContext[/DBTest]: Starting
>2002-07-08 16:14:38 StandardContext[/DBTest]: Processing start(), current
>available=false
>2002-07-08 16:14:38 StandardContext[/DBTest]: Configuring default 
Resources
>2002-07-08 16:14:38 StandardContext[/DBTest]: Error initializing 
resources:
>Document base /home/tomcat/jwsdp-1_/webapps/DBTest does not exist or is 
not
>a readable directory
>2002-07-08 16:14:38 StandardContext[/DBTest]: Configuring non-privileged
>default Loader
>2002-07-08 16:14:38 StandardContext[/DBTest]: Configuring default Manager
>2002-07-08 16:14:38 StandardContext[/DBTest]: Processing standard 
container
>startup
>2002-07-08 16:14:38 StandardContext[/DBTest]: Context startup failed due 
to
>previous errors
>2002-07-08 16:14:38 StandardContext[/DBTest]: Exception during cleanup
>after start failed
>LifecycleException:  Container StandardContext[/DBTest] has not been
>started
>        at
>org.apache.catalina.core.StandardContext.stop(StandardContext.java:3521)
>        at
>org.apache.catalina.core.StandardContext.start(StandardContext.java:3499)
>        at
>org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1190)
>        at
>org.apache.catalina.core.StandardHost.start(StandardHost.java:739)
>        at
>org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1190)
>        at
>org.apache.catalina.core.StandardEngine.start(StandardEngine.java:347)
>        at org.apache.catalina.core.StandardService.start(StandardServic
>e.java:499)
>        at
>org.apache.catalina.core.StandardServer.start(StandardServer.java:2187)
>        at org.apache.catalina.startup.Catalina.start(Catalina.java:504)
>        at org.apache.catalina.startup.Catalina.execute(Catalina.java:399)
>        at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
>a:39)
>        at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
>Impl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:324)
>        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
>a:39)
>
>
>I am not an expert, but I feel like I have to be to get DBCP to work....
>
>
>
>clay
>
>
>--
>To unsubscribe, e-mail: 
  <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to