tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From echam...@TXU.COM
Subject Re: Context/DBCP mess...
Date Wed, 09 Oct 2002 19:35:46 GMT

Michael:

I had the same problem. Mine was an issue about where I placed the Resource
and Resource Parameters. Make sure both are embedded
within the Context you are attempting to pull the datasource from.

Also, DBCP (Database Connection Pooling) is not enabled with the given
configuration. To use DBCP, you must download the DBCP
package from Apache Commons project and implement the factory tag within
the ResourceParams tag.

With Tomcat 4.1.x, this is done automatically with global database
resources which is a main reason I am moving to the new version when
I believe many of the problems users are having are taken care of.

Hope this helps,
Ej




"Michael Nicholson" <man@email.unc.edu> on 10/09/2002 02:08:34 PM

Please respond to "Tomcat Users List" <tomcat-user@jakarta.apache.org>

To:    "Tomcat Users List" <tomcat-user@jakarta.apache.org>
cc:

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








**********************************************************************************
Confidentiality Notice: This email message, including any attachments, 
contains or may contain confidential information intended only for the 
addressee. If you are not an intended recipient of this message, be 
advised that any reading, dissemination, forwarding, printing, copying
or other use of this message or its attachments is strictly prohibited. If
you have received this message in error, please notify the sender 
immediately by reply message and delete this email message and any
attachments from your system.  
**********************************************************************************


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message