You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Bowen <kb...@als.com> on 2007/07/15 03:30:36 UTC
DataSources and Tomcat (continue thread: Re: How to use connection
pool with tomcat 1.2.9)
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 javauser@localhost 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: DataSources and Tomcat (continue thread: Re: How to use connectionpool with tomcat 1.2.9)
Posted by Lyallex <ly...@gmail.com>.
You left this bit out
... it's not a criticism before anyone gets upset
I'd be glad to contribute to the documentation, just gotta figure out
how, guess I'll have to RTFM.
Rgds
Duncan
On 7/15/07, Mark Thomas <ma...@apache.org> wrote:
> Lyallex wrote:
> > One thing that constantly frustrates me is the apparent ambiguities in
> > the documentation
>
> Then do something constructive about it. You are part of the Tomcat
> community and the documentation is as much your responsibility as
> anyone else here. If you find a problem, report it. Better yet,
> suggest an alternative wording that improves the documentation or
> ideally, provide a patch.
>
> > 'Add this in between the </Context> tag of the examples context and
> > the </Host> tag closing the localhost definition'
> > Well there isn't a Context tag in my distro so I just invented one and
> > it works, of course we are always being advised to put our <Context>
> > thing in our web apps these days so that's what I'm going to try next.
>
> This has been now fixed in the docs 5.5.x and 6.0.x and will be in the
> next release of each.
>
> Mark
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: DataSources and Tomcat (continue thread: Re: How to use connectionpool
with tomcat 1.2.9)
Posted by Mark Thomas <ma...@apache.org>.
Lyallex wrote:
> One thing that constantly frustrates me is the apparent ambiguities in
> the documentation
Then do something constructive about it. You are part of the Tomcat
community and the documentation is as much your responsibility as
anyone else here. If you find a problem, report it. Better yet,
suggest an alternative wording that improves the documentation or
ideally, provide a patch.
> 'Add this in between the </Context> tag of the examples context and
> the </Host> tag closing the localhost definition'
> Well there isn't a Context tag in my distro so I just invented one and
> it works, of course we are always being advised to put our <Context>
> thing in our web apps these days so that's what I'm going to try next.
This has been now fixed in the docs 5.5.x and 6.0.x and will be in the
next release of each.
Mark
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: DataSources and Tomcat (continue thread: Re: How to use connectionpool
with tomcat 1.2.9)
Posted by Ken Bowen <kb...@als.com>.
Indeed. Simply swapping the Context given in
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html,
in for the Context given in
http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html
makes the 4.1 example work. This way makes it clear what has changed.
Thanks very much.
Ken
Lyallex wrote:
> Hi
>
> How confused do you want to be ....
>
> I started looking at the 4.1 docs as well ... it'll never work
> I do object to having to download taglibs just to get a simple example
> working so you can keep all the code from the 4.1 example including
> the web.xml entry
> All you really need to change is the server.xml configuration as
> described in
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html,
>
> at least this is what I did and the example seems to work OK.
>
> One thing that constantly frustrates me is the apparent ambiguities in
> the documentation (it's not a criticism before anyone gets upset) the
> docs state
> 'Add this in between the </Context> tag of the examples context and
> the </Host> tag closing the localhost definition'
> Well there isn't a Context tag in my distro so I just invented one and
> it works, of course we are always being advised to put our <Context>
> thing in our web apps these days so that's what I'm going to try next.
>
> Good Luck
>
> Chers
> Duncan
>
> On 7/15/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
>> > From: Ken Bowen [mailto:kbowen@als.com]
>> > Subject: DataSources and Tomcat (continue thread: Re: How to
>> > use connectionpool with tomcat 1.2.9)
>> >
>> > 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.h
>> tml
>>
>> If you're using 5.5, why are you spending any time looking at the 4.1
>> documentation? Try using the correct doc for the level you have:
>> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h
>> tml
>>
>> - Chuck
>>
>>
>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
>> MATERIAL and is thus for use only by the intended recipient. If you
>> received this in error, please contact the sender and delete the e-mail
>> and its attachments from all computers.
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: DataSources and Tomcat (continue thread: Re: How to use connectionpool with tomcat 1.2.9)
Posted by Lyallex <ly...@gmail.com>.
Hi
How confused do you want to be ....
I started looking at the 4.1 docs as well ... it'll never work
I do object to having to download taglibs just to get a simple example
working so you can keep all the code from the 4.1 example including
the web.xml entry
All you really need to change is the server.xml configuration as described in
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html,
at least this is what I did and the example seems to work OK.
One thing that constantly frustrates me is the apparent ambiguities in
the documentation (it's not a criticism before anyone gets upset) the
docs state
'Add this in between the </Context> tag of the examples context and
the </Host> tag closing the localhost definition'
Well there isn't a Context tag in my distro so I just invented one and
it works, of course we are always being advised to put our <Context>
thing in our web apps these days so that's what I'm going to try next.
Good Luck
Chers
Duncan
On 7/15/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
> > From: Ken Bowen [mailto:kbowen@als.com]
> > Subject: DataSources and Tomcat (continue thread: Re: How to
> > use connectionpool with tomcat 1.2.9)
> >
> > 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.h
> tml
>
> If you're using 5.5, why are you spending any time looking at the 4.1
> documentation? Try using the correct doc for the level you have:
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h
> tml
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: DataSources and Tomcat (continue thread: Re: How to use connectionpool with tomcat 1.2.9)
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ken Bowen [mailto:kbowen@als.com]
> Subject: DataSources and Tomcat (continue thread: Re: How to
> use connectionpool with tomcat 1.2.9)
>
> 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.h
tml
If you're using 5.5, why are you spending any time looking at the 4.1
documentation? Try using the correct doc for the level you have:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h
tml
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org