I see this come up a lot in this user list and others about Tomcat, so I want to share
this information. Note that the solution described below allows you to access a
global data source from all Web Applications, without putting the <Resource> or
<ResourceParams> elements in each Web Application <Context>.
For over a week, I have been fighting the problem of configuring a data source so
that it can be accessed by multiple Web Applications. I finally got it to work with
Tomcat 5.0.9, by following Paul's advise from 9/12/03. I had no luck with Tomcat
versions 4.1.24 or 4.1.27. To make it work in Tomcat 5.0.9, I used the Tomcat
Administration tool to add the data source. It puts the following two elements in the
<GlobalNamingResources> element:
1. <Resource>
2. <ResourceParams>
I am working SQLServer 2000, using Microsoft's JDBC driver (wonders never cease):
<GlobalNamingResources>
<Resource auth="Container"
name="MyDataSource"
scope="Shareable"
type="javax.sql.DataSource"/>
<ResourceParams name="MyDataSource">
!-- etc. -->
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://111.111.111.111:1433;database=mydb</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<!-- etc. -->
<parameter>
<name>username</name>
<value>myusername</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
Then I added a <Context> element for my Web Application-- it is the first child of the
<Host> element:
<Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true"
crossContext="false"
debug="0"
displayName="Welcome to Tomcat"
docBase="/usr/local/jakarta-tomcat-5.0.9/webapps/myWebApp"
mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/myWebApp"
privileged="false"
reloadable="false"
swallowOutput="false"
useNaming="true"
wrapperClass="org.apache.catalina.core.StandardWrapper">
<ResourceLink name="MyDataSource"
global="MyDataSource"
type="javax.sql.DataSource"/>
</Context>
Note that it was NOT necessary to add a <resource-ref> element to the web.xml for the
Web Application.
-----Original Message-----
From: SANTOS, DANIEL (SBCSI) [mailto:[EMAIL PROTECTED]
Sent: Fri 9/19/2003 11:20 AM
To: '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL
PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'
Cc: '[EMAIL PROTECTED]'
Subject: SOLUTION!! -- Cannot load JDBC driver class 'null'
Using Sun JDK 1.4.1_02 on Win2k SP2 and Jakarta 4.1.27.
The tutorial in the tomcat docs failed for me also with the Cannot load JDBC
driver class 'null'. I banged my head and had to get stitches and an ice
pack. After that I came back to the office and cleaned out my server.xml and
web.xml completely. Then I went to http://localhost:8080/admin
<http://localhost:8080/admin> , browsed to the context that I am writing my
app in, the full path from the tree being "Tomcat Server/Service
(Tomcat-Standalone)/Host (localhost)/Context(/myapp)/Resources/Data
Sources". I added the data source from there specifying the JNDI name,
driver class, URL, user and pass, etc. Then I did some tests with a jsp to
make sure it was really in my context (you may have to restart tomcat, I
did).
Next I added the code back into my web.xml that is in the tutorial....
<resource-ref>
<description>DB Connection</description>
<res-ref-name>myData Source</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
And it works!!! I just have a new problem now of DBCP borrowObject failed:
String index out of range: -1, I suppose I'll figure that out too...
Good Luck and thanks to all who posted info on this,
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]