Hi,

Your server.xml looks fine.

If you specify the resource in server.xml there is no need to put it in web.xml (in 
fact this will more than likely cause problems).

You should reference the datasource in your app as follows:

    ctx = new InitialContext();
    Context envCtx = (Context) ctx.lookup("java:/comp/env/");
    DataSource ds = (DataSource) envCtx.lookup("/juddidb");

The class.forName() is used when you are not using DBCP but directly connecting.

Make sure that the Oracle classes12.zip is renamed to classes12.jar and in 
CATALINA_HOME/common/lib

HTH

Eric

-----Original Message-----
From: Ravi Rangaswamy [mailto:[EMAIL PROTECTED]]
Sent: Donnerstag, 16. Jänner 2003 21:38
To: TomcatUserList
Subject: Help With Tomcat Database Connection Configuration



Hi,

I am running a UDDI registry (CATALINA_HOME/web-apps/juddi) from inside Tomcat. Now I 
want to run the registry with Oracle. So, I created a JDBC datasource in Tomcat. To do 
this, I followed these steps.


1. I added the segment in CATALINA_HOME/conf/server.xml inside the <context> element.

          <!-- Orcale JDBC datasource for jUDDI -->
          <Resource name="jdbc/juddidb" auth="Container"
              type="javax.sql.DataSource"/> 

          <ResourceParams name="jdbc/juddidb">
            <parameter>
              <name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter>
              <name>driverClassName</name>
              <value>oracle.jdbc.driver.OracleDriver</value>
            </parameter>
            <parameter>
              <name>url</name>
              <value>jdbc:oracle:thin:@localhost:1521:orcl</value>
            </parameter>
            <parameter>
              <name>username</name>
              <value>juddiUser</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>juddiUser</value>
            </parameter>
            <parameter>
              <name>maxActive</name>
              <value>20</value>
            </parameter>
            <parameter>
              <name>maxIdle</name>
              <value>10</value>
            </parameter>
            <parameter>
              <name>maxWait</name>
              <value>5000</value>
            </parameter>
          </ResourceParams>
          <!-- End of Orcale JDBC datasource for jUDDI -->


2. I added this segment in CATALINA_HOME/web-apps/juddi/WEB_INF/web.xml inside the 
<web-app> element.

 <!-- Orcale JDBC datasource for jUDDI -->
 <resource-ref>
  <description>Oracle Datasource</description>
  <res-ref-name>jdbc/juddidb</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>

When I start Tomcat and invoke a action on jUDDI, I get the exception

Cannot load JDBC driver class 'null'
java.lang.NullPointerException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:140)
        at 
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:523)
        at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)


So, to further debug, I added the segment from Step 2 to 
CATALINA_HOME/web-apps/examples/WEB_INF/web.xml and created a jsp (shown at the end of 
the mail) to see if it was picking up the configuration parameters. When this jsp is 
executed, I get the following displayed with the parameters as specified in server.xml.

 DriverClassName: oracle.jdbc.driver.OracleDriver Url: 
jdbc:oracle:thin:@localhost:1521:orcl Username: juddiUser Password: juddiUser 
MaxActive: 20 MaxWait: 5000 NumActive: 3 numIdle: 0

If I place the same jsp under CATALINA_HOME/web-apps/juddi/jsp/..... and run the jsp, 
I get nulls for each param

 DriverClassName: null Url: null Username: null Password: null MaxActive: 8 MaxWait: 
-1 NumActive: 0 numIdle: 0

Can anyone tell me what I am doing wrong and why these two applications (examples and 
the uddi registry) behave differently.

Thanks,
Ravi.

 

Test jsp
--------

<%@ page language="java" 
import="java.sql.*,javax.naming.InitialContext,javax.naming.Context,javax.sql.DataSource,org.apache.commons.dbcp.BasicDataSource"
 %>

<body bgcolor="white">
<font color="red">

<% 
Connection conn = null;

try {


InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:comp/env");
DataSource ds = (DataSource)context.lookup("jdbc/juddidb");

out.print(" DriverClassName: " + ((BasicDataSource) ds).getDriverClassName());
out.print(" Url: " + ((BasicDataSource) ds).getUrl());
out.print(" Username: " + ((BasicDataSource) ds).getUsername());
out.print(" Password: " + ((BasicDataSource) ds).getPassword());
out.print(" MaxActive: " + ((BasicDataSource) ds).getMaxActive());
out.print(" MaxWait: " + ((BasicDataSource) ds).getMaxWait());
out.print(" NumActive: " + ((BasicDataSource) ds).getNumActive());
out.print(" numIdle: " + ((BasicDataSource) ds).getNumIdle());

} catch (Exception e) {
      e.printStackTrace();
}

%>



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to