RE(David Smith): though I'm guessing that this thread is over and
nobody will read this follow-up. :(
Change to: :) -- at least one follow-up reader.
RE(Chris Shultz):
|> As I said, i did declare the tomcat dataSource in server.xml and
|> WEB-INF/web.xml.
|
|Don't do that. Since you're using Tomcat 5.5, you should declare your
|DataSource in META-INF/context.xml, along with your Realm. Then, you
|don't ever have to touch server.xml, which is nice.
I also want to get the Tomcat DataSource machinery working.
I'm using Tomcat 5.5.9.
I've slavishly followed the mySQL example in
http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html
But I get:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'
[I eventually want to follow the advice above, but don't know where to
locate the descriptions of how to carry out the META-INF type of
declaration.
Right now, I want to understand why the example fails. ]
I'm working on Windows (not necessarily by choice) and $CATALINA_HOME =
C:\Tomcat.
The following jars (among others) are present in $CATALINA_HOME/common/lib/
commons-collections-3.2.jar
commons-dbcp-1.2.2.jar
commons-pool-1.3.jar
mysql-connector-java-3.1.14-bin.jar
The database has been created and populated using the given commands
(wrapped in a file DBTest.sql:
GRANT ALL PRIVILEGES ON *.* TO [EMAIL PROTECTED] IDENTIFIED BY
'javadude' WITH GRANT OPTION;
create database javatest;
use javatest;
create table testdata (id int not null auto_increment primary key,
foo varchar(25), bar int);
insert into testdata values(null, 'hello', 12345);
---------------------------------------------------------------------
mysql> select * from testdata;
+----+-------+-------+
| id | foo | bar |
+----+-------+-------+
| 1 | hello | 12345 |
+----+-------+-------+
1 row in set (0.00 sec)
[Connected to mysql using: mysql -u javauser -pjavadude ]
I copied the Context (cut/paste) into server.xml --- I'll append
that at the end of the message.
Here's the web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>MySQL Test App</description>
<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>
</web-app>
The jsp is in the file jsp/test_v4.jsp, with folder jsp at the same
level as WEB-INF:
<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>
Here is catalina.out when Tomcat is started:
exec ./catalina.sh start -Dcatalina.base= tomcat5.exe
Using CATALINA_BASE: c:\Tomcat
Using CATALINA_HOME: c:\Tomcat
Using CATALINA_TMPDIR: c:\Tomcat\temp
Using JRE_HOME: c:\Program Files\Java\jdk1.5.0
usage: java org.apache.catalina.startup.Catalina [ -config
{pathname} ] [ -nonaming ] { start | stop }
Jul 14, 2007 9:13:22 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jul 14, 2007 9:13:22 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 781 ms
Jul 14, 2007 9:13:22 PM org.apache.catalina.core.StandardService
start
INFO: Starting service Catalina
Jul 14, 2007 9:13:22 PM org.apache.catalina.core.StandardEngine
start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
Jul 14, 2007 9:13:22 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jul 14, 2007 9:13:23 PM org.apache.coyote.http11.Http11Protocol
start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jul 14, 2007 9:13:23 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 14, 2007 9:13:23 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/20 config=null
Jul 14, 2007 9:13:23 PM
org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jul 14, 2007 9:13:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1131 ms
I point the browser at: http://localhost:8080/DBTest/jsp/test_v4.jsp
The browser result is:
Results
Foo Not Connected
Bar -1
The (reduced) stacktrace is:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
....
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
And here is the server.xml used:
<Server port="8005" shutdown="SHUTDOWN">
<!-- Comment these entries out to disable JMX MBeans support used for the
administration web application -->
<Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener
className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3" />
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<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>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>javauser</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
</Server>
I'll really appreciate any help getting over this problem. [Then I'd
like to move on
to the META-INF -oriented approach.]
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]