Hi Michael,
Have you tried this with Tomcat 4.1.x? Many bugs have been fixed and you
may have better luck.
Rick
----- Original Message -----
From: "Michael Nicholson" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, October 09, 2002 3:08 PM
Subject: Context/DBCP mess...
I'm sure we're all tired of reading about these problems (and God knows I'm
tired of pounding my head against a wall because of them), but I can't seem
to get the contexts and connectionpooling/datasources working.
For starters:
Local Development Machine: pIII450, 512MB ram, win2000, tomcat 4.03 through
sun one studios/forte
Remote Development Machine: SunOS, 1Gig ram, tomcat 4.03 standalone
The problem:
I've attempted to configure my app to use a JDBC DataSource by changing the
server.xml and web.xml files. The resource tags in the server.xml are:
<Resource name="jdbc/myoracle" auth="Container" type="javax.sql.Datasource"
/>
<ResourceParams name="jdbc/myoracle">
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:oracle:thin:@oracle.host.blah:1521:ORCL</value>
</parameter>
<parameter>
<name>username</name>
<value>scott</value>
</parameter>
<parameter>
<name>password</name>
<value>tiger</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
These are the connection strings and parameters that I use to successfully
connect the database by manually registering the driver and simply making a
connection.
The web.xml has:
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
So, I saw the JndiServlet example, and modified it to spit out whatever I
had bound to my context both by looking to the initial context and my
environmental context (which, yes, I know, is part of the initial context,
but I'm stumped, so I'm trying most anything I can think of). This is the
code:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/myoracle");
if(ds!=null)
{
Connection conn = ds.getConnection();
}
else
{
out.println("DataSource ds is null<br>");
}
//This page tests the database connection pool.
//
//Imported from JndiServlet.java in examples folder
NamingEnumeration enum =
initContext.list("java:/comp/env/jdbc");
while (enum.hasMoreElements()) {
out.print("Binding : ");
out.println(enum.nextElement().toString());
}
enum = envContext.listBindings("jdbc");
out.println("<br>listBindings1() on /comp/env/jdbc Context : ");
//enum = initContext.listBindings("java:/comp/env/jdbc");
while (enum.hasMoreElements()) {
out.print("Binding : ");
out.println(enum.nextElement().toString());
}
out.println("<br>listBindings2() on /comp/env/jdbc Context : ");
enum = initContext.listBindings("java:/comp/env/jdbc");
while (enum.hasMoreElements()) {
out.print("Binding : ");
out.println(enum.nextElement().toString());
}
%>
So, anytime I try it, ta-dah! The datasource is null. However, the output
shows this:
DataSource ds is null
Binding : myoracle: org.apache.naming.ResourceRef
listBindings1() on /comp/env/jdbc Context : Binding : myoracle:
org.apache.naming.ResourceRef:Reference Class Name: javax.sql.DataSource
Type: description Content: Oracle Datasource example Type: scope Content:
Shareable Type: auth Content: Container Type: maxWait Content: -1 Type:
maxActive Content: 20 Type: password Content: tiger Type: driverName
Content: jdbc:oracle:thin:@oracle.host.blah:1521:ORCL Type: driverClassName
Content: oracle.jdbc.driver.OracleDriver Type: maxIdle Content: 10 Type:
username Content: scott
listBindings2() on /comp/env/jdbc Context : Binding : myoracle:
org.apache.naming.ResourceRef:Reference Class Name: javax.sql.DataSource
Type: description Content: Oracle Datasource example Type: scope Content:
Shareable Type: auth Content: Container Type: maxWait Content: -1 Type:
maxActive Content: 20 Type: password Content: tiger Type: driverName
Content: jdbc:oracle:thin:@oracle.host.blah:1521:ORCL Type: driverClassName
Content: oracle.jdbc.driver.OracleDriver Type: maxIdle Content: 10 Type:
username Content: scott
So it looks like it can find all of the information for this datasource...
and yet, no datasource?
Any suggestions? Please... my head hurts as it is...:)
Thanks for your time...
Michael Nicholson
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>