The error msg makes me unsure of the problem you are having. You could
either be having a JNDI problem or a DBCP problem.
To identify this, try adding this code
//*********************
Try {
Context invCtx = new InitialContext();
if(invCtx == null ) throw new Exception("Boom - No Initial
Context");
Context envCtx = (Context) invCtx.lookup("java:comp/env");
if(envCtx == null ) throw new Exception("Boom - No Environmental
Context");
DataSource ds = (DataSource) envCtx.lookup("jdbc/ospreyDb");
}
//*********************
If you do not get either thrown exception, it is probably a DBCP
problem.
BTW, DBCP is dependent on a few other jars being in place.
Make sure you have these libraries from the Jakarta-Commons project:
commons-pool.jar
commons-collections.jar
commons-logging-api.jar
And get the latest nightly build of commons-dbcp.jar
2002-07-02 or later (there were some recent fixes).
- Andrew
-----Original Message-----
From: Meichun Li [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 04, 2002 1:40 PM
To: Tomcat Users List
Subject: RE: Connection Pooling?
Thanks for the help!
I followed the steps in the howto page
http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2
I compiled my java test file and there is no error message. But when I
run
it, I run it, I got the error message as below.Could anyone please give
me
some hints? Thanks a lot!
javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:647)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:2
84)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.ibiblio.pool.DataSourceBean.main(DataSourceBean.java:24)
More detail below:
1. My system already has these installed:
jakarta-tomcat-4.0.1
J2SE 1.3
mysql-3.23.33
mm.mysql-2.0.7
2. I download Jakarta-Commons projects
DBCP Nightly Build 20020620. (The Nightly Build 20020523 couldn't
be
found).
collections 2.0
pool 1.0
I put the mm.mysql, DBCP, collection and pool jar files into
CATALINA_HOME/common/lib
3. I already have a DB called osprey in mySQL.
4. Then I configured the context in the server.xml:
<Context path="/osrt/osprey/webapps"
docBase="/public/html/osrt/osprey/webapps"
debug="0"
reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/ospreyDb" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ospreyDb">
<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>user</name><value>****</value></parameter>
<parameter><name>password</name><value>***</value></parameter>
<parameter><name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:mysql://trance.metalab.unc.edu:3306/osprey</value></paramete
r>
</ResourceParams>
</Context>
5. I changed my WEB-INF/ web.xml by adding the <resource-ref> stuff.
<?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>
<taglib>
<taglib-uri>
/orataglib
</taglib-uri>
<taglib-location>
/WEB-INF/tlds/orataglib_1_0_3.tld
</taglib-location>
</taglib>
<resource-ref>
<res-ref-name>jdbc/ospreyDb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
6. I have a java file in WEB-INF/classes/org/ibiblio/pool call
DataSourceBean.java
//Testing
package org.ibiblio.pool;
import java.lang.*;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.naming.*;
import javax.naming.spi.*;
public class DataSourceBean{
public static void main (String arg[])
{
try{
Context ctx = new InitialContext();
if(ctx == null ) throw new Exception("Boom - No Context");
DataSource ds
=(DataSource)ctx.lookup("java:comp/env/jdbc/ospreyDb");
} catch(Exception e) {
e.printStackTrace();
}
}//end of main
} // end of class
The error is from the line
DataSource ds =(DataSource)ctx.lookup("java:comp/env/jdbc/ospreyDb");
On Thu, 4 Jul 2002, Les Hughes wrote:
> I think I should set up a cron job to email this link out every
> day....
>
> http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2
>
>
>
> > -----Original Message-----
> > From: Meichun Li [mailto:[EMAIL PROTECTED]]
> > Sent: 04 July 2002 13:09
> > To: Tomcat Users List
> > Subject: Connection Pooling?
> >
> >
> > Hi,
> > I want to implement my application with Connection Pooling.
> >
> > Tomcat offers supports of a connection pool for JDBC
> > connection, but there
> > should be a prerequisite--JDBC driver should provide pooled
> > datasource
> > implementation. Is this right?
> >
> > The JDBC driver for MySQL database I am using is
> > org.gjt.mm.mysql. The
> > driver has the class MysqlDataSource that is a JNDI DataSource for
> > Mysql JDBC connection-- only the basic
> > implementation of javax.sql.Datasource but not connection pool
> > implementation.
> >
> > Is this means that I can't use connection pool with this
> > JDBC driver in
> > tomcat?
> >
> > Thanks!
> >
> > Meichun
> >
> >
> > --
> > Meichun Li
> > Ibiblio.org
> > 919-962-5646
> >
> >
> > --
> > 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]>
>
--
Meichun Li
Ibiblio.org
919-962-5646
--
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]>