Tomcat's database pooling implements a slightly refactored version of
the Commons DBCP project -- packages were renamed to avoid conflicts
should a developer decide to use the Commons DBCP library in their own
app. You can find a complete list of possible attributes for the
Resource definition here:
http://commons.apache.org/dbcp/api-1.2.2/org/apache/commons/dbcp/BasicDataSource.html
Just look at the setters -- remove the word set from the beginning of
the method name and drop the case on the first letter after 'set'. For
example, if you want access setValidationQuery(), you would drop set and
lower case the V for validationQuery="" in your <Resource ../> definition.
--David
Ken Bowen wrote:
David,
Bingo! Right on: Changed all permissions (chown -R tomcat myapp),
and dropped the mysql jar from WEB-INF/lib, and
it all works. Many thanks! I do hate it when I forget simple stuff
like permissions. Moving things from Windows to *nix
always does that to me.
Side note question: Am I correct that the following is the intended
xml?:
<Resource name="jdbc/sb_data" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
validationQuery="select 1"
username="sb_normal" password="********"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sb_data"/>
Where could I read more about these kinds of details?
Thanks again,
Ken Bowen
David Smith wrote:
Don't 'copy' the mysql driver from WEB-INF/lib to
TOMCAT_HOME/common/lib -- move it. It cannot be in both places at
once. Also be sure the permissions are set correctly so tomcat can
read the jar and be sure you've restarted tomcat after the move so
the classloaders pick it up properly. I have no idea why it works in
Windows at all unless the Windows install has a copy of it in
common/lib already -- which can cause problems later on if it's also
in WEB-INF/lib.
As a side note (and this is becoming a mantra with me) please don't
use ?autoReconnect=true in your jdbc url. Instead add the attribute
validationQuery="select 1" in the Resource element. That tells the
pool how to validate the connection and optionally regenerate it
before you borrow.
--David
Ken Bowen wrote:
Hello,
I'm working on a CENTOS 5 Linux setup.
I'm trying to avoid the pre-loaded tomcat which was installed in
/usr/share/tomcat5.
I downloaded (from apache) and installed tomcat5.5.25 and installed
it in /opt/tomcat5.
I made sure the existing tomcat is not running and I renamed
/usr/share/tomcat5.
I start it (the new tomcat) with /opt/tomcat5/bin/startup.sh and it
runs fine:
Tomcat manager runs and I can start/stop the built-in apps.
I have an app which I developed using tomcat5.5.9 on Windows, and I
am trying to
transfer it to this Linux setting.
I placed my exploded app in webapps. The app wants to use a Mysql
database named sb_data.
The same database as on Windows has been replicated in Mysql in the
Linux setup.
I have the following context.xml in my META-INF folder:
<Context path="/myapp" docBase="myapp"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/sb_data" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="sb_normal" password="********"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sb_data?autoReconnect=true"/>
</Context>
My application has a registered AppListener in which I establish the
DataSource
in the contextInitialized method and use it to do some initial work
with the database:
System.out.println("MyApp AppListener: ENTER");
....
Context envCtx = (Context)
initialContext.lookup("java:comp/env");
String key = "jdbc" + "/" + "sb_data";
DataSource ds = (DataSource)envCtx.lookup(key);
if (ds != null ){
DAOBaseData.setDataSource(ds);
}
....
...CALL to DAOBaseData.getConnection(); HERE
....
System.out.println("MyApp AppListener: EXIT");
The code for getConnection() looks like this:
public Connection getConnection() throws DAOException
{
Connection connection = null;
if (datasource!= null) {
try {
connection = datasource.getConnection();
} catch (SQLException e) {
//TODO: Log this
String message = e.getMessage();
System.out.println("DAOBaseData: "+message);
throw new DAOException(message);
}
}
connCount++;
System.out.println("Connection[data] allocated:
#="+connCount);
return connection;
}
This works ok on Windows, but in the Linux setting I get the
following error in
the catalina.out log:
MyApp AppListener: ENTER
DAOBaseData: Cannot load JDBC driver class
'com.mysql.jdbc.Driver'
com.myapp Error: Cannot load JDBC driver class
'com.mysql.jdbc.Driver'
MyApp AppListener: EXIT
I'm using the mysql-connector-java-3.1.14-bin.jar and it is present
in WEB-INF/lib.
I tried copying it to /opt/tomcat5/common/lib , but I still get the
same error.
I'm confused. Why does tomcat on Windows find the JDBC driver, but
not find it on Linux?
Thanks in advance,
Ken Bowen
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]