David Smith wrote:
Yes, remove all copies except one and that one should be in the
common/lib directory. It has to be in common/lib to essentially be
visible to both tomcat internal code as well as all the webapps. There
can't be a copy anywhere else in tomcat because ... well .... I'll let
the classloader how-to on tomcat's website explain that:
http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
(assuming you have tomcat 5.5.x).
What it comes down to is there can't be two of the same class (package
name and class name) visible from different classloaders. Tomcat
internal code will see the one in common/lib first, your webapps will
see it's own copy first and you'll end up with many a wonderous and
strange error to ask us about.
Tomcat already contains all DBCP/Pool classes it needs to provide the
DataSources configured in server.xml or context.ml. Look at the contents of
${CATALINA_HOME}/common/lib/naming-factory-dbcp.jar
It contains dbcp, but in a repackaged form (name of Java package
changed, so that it doesn't collide with webapp provided ones). It is
also mentioned shortly in the RELEASE-NOTES file in ${CATALINA_HOME}.
Regards,
Rainer
--David
jerrycat wrote:
No,
I have commons-dbcp.1.2.2 jar in the lib directory of all of my web
app as
well.
Should I remove the commons-dbcp1.2.2.jar from the web apps
and put the jar files in the common/lib directory.
The jar files are:
commons-dbcp-1.2.2
commons-pool-1.3
I assume that the naming-factory-dbcp.jar that comes with tomcat under
common/lib
do not include the above jars.
Thanks again.
David Smith-2 wrote:
When getting the DataSource (Or BasicDataSource in my case) from
tomcat's
JNDI/JDBC service
does Tomcat manage the connection pooling itself.
Essentially yes. You still have to be sure you close your database
objects, but the rest is done by DBCP.
Do I just need to retrieve the DataSource and then get the
Connection and
close the Connection
after usage?
Yes. Implement finally blocks on your try/catch exception management
to guarantee they are closed and returned to the database pool
regardless of outcome.
Or do I have to include a few lines of complicated as above as well?
Nope. The BasicDataSourceFactory class will handle that stuff for
you. The code you cite below looks like it's for when you are
creating the pool and managing it yourself, which you aren't doing in
this case.
Also you didn't mention it, but I'm assuming your one and only copy
of the DBCP jar file is in common/lib for tomcat 5 or /lib for tomcat 6,
right?
--David
jerrycat wrote:
I have configured my web app to use tomcat's connection pooling.
and also I have modfied the default value of the factory attribute:
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
Here is the context.xml
<Context>
<Resource name="jdbc/testDB"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
auth="Container" type="javax.sql.DataSource"
maxActive="10" maxIdle="5" maxWait="10000"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
username="username" password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" />
</Context>
Here is how I retrieve the data source so that I later can ask for a
connection:
private static BasicDataSource ds = null;
public static DataSource getDataSource() throws SQLException {
if (ds == null) {
try {
final Context initContext = new InitialContext();
ds =
(BasicDataSource)initContext.lookup("java:/comp/env/jdbc/testDB");
initContext.close();
logDataSource(ds);
return ds;
} catch (final NamingException e) {
e.printStackTrace();
throw new RuntimeException("Java naming exception
when getting
connection from tomcat pool: " + e.getMessage());
}
} else {
logDataSource(ds);
return ds;
}
}
I have read somewhere that you have to create a PoolingDataSource if
you
want
use connection pooling.
Here is a sample code that I have found:
GenericObjectPool connectionPool = new GenericObjectPool(null);
DriverManagerConnectionFactory connectionFactory = new
DriverConnectionFactory("jdbc:some:connect:string",null);
PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
Question:
When getting the DataSource (Or BasicDataSource in my case) from
tomcat's
JNDI/JDBC service
does Tomcat manage the connection pooling itself.
Do I just need to retrieve the DataSource and then get the
Connection and
close the Connection
after usage?
Or do I have to include a few lines of complicated as above as well?
Thanks!
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]