Hi,

Try using the GlobalNamingResource element instead of the Context element, then put a 
ResourceLink to that resource in each Host element.

If the resource is defined in either Context or GlobalNamingResource in server.xml , 
there is no need to include any reference to it in web.xml as a lookup to the 
InitialContext will resolve the resource.

Regards

Eric

-----Original Message-----
From: Nate Drake [mailto:[EMAIL PROTECTED]]
Sent: Donnerstag, 09. Jänner 2003 15:48
To: [EMAIL PROTECTED]
Subject: Connection Pool problem with virtual hosts


Hi,

I'm having trouble when attempting to access a JDBC connection pool when
using a virtual host.  I have a servlet that is set to load on startup (ie.
<load-on-startup>1</load-on-startup> in web.xml), this servlet attempts to
get a pool connection to read some configuration options from the database.
This works fine when the web app is deploy without using virtual hosts.
When attempting to run with virtual hosts I get the following error: "Could
not load JDBC driver 'null'".  I've seen this error reported many times on
the list, with no definite solution that has worked.

Here is information about my setup:

Tomcat Standalone, version 4.1.12

Oracle database

Solaris 8 and 9

web.xml for pool:

    <resource-ref>
      <description>Oracle Datasource</description>
      <res-ref-name>jdbc/orapool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>

server.xml for virtual host:

      <Host name="blah.blah.com" debug="0" appBase="blah"
       unpackWARs="true" autoDeploy="true">

        <!-- Logger shared by all Contexts related to this virtual host.  By
             default (when using FileLogger), log files are created in the
"logs"
             directory relative to $CATALINA_HOME.  If you wish, you can
specify
             a different directory with the "directory" attribute.  Specify
either a
             relative (to $CATALINA_HOME) or absolute path to the desired
             directory.-->
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="blah_log." suffix=".txt"
                timestamp="true"/>

        <!-- Define properties for each web application.  This is only
needed
             if you want to set non-default properties, or have web
application
             document roots in places other than the virtual host's appBase
             directory.  -->

        <!-- Tomcat Root Context -->
          <Context path="" docBase="blahweb" debug="4">

            <Resource name="jdbc/orapool" auth="Container"
                      type="javax.sql.DataSource"/>

            <ResourceParams name="jdbc/orapool">
                <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>validationQuery</name>
                    <value>select sysdate from dual</value>
                </parameter>
                <parameter>
                    <name>removeAbandoned</name>
                    <value>true</value>
                </parameter>
                <parameter>
                    <name>removeAbandonedTimeout</name>
                    <value>60</value>
                </parameter>
                <parameter>
                    <name>logAbandoned</name>
                    <value>true</value>
                </parameter>
                <parameter>
                    <name>maxWait</name>
                    <value>30000</value>
                </parameter>
                <parameter>
                    <name>maxActive</name>
                    <value>20</value>
                </parameter>
                <parameter>
                    <name>maxIdle</name>
                    <value>10</value>
                </parameter>
                <parameter>
                    <name>password</name>
                    <value>mypassword</value>
                </parameter>
                <parameter>
                    <name>url</name>

<value>jdbc:oracle:thin:@192.168.0.100:1521:mysid</value>
                </parameter>
                <parameter>
                    <name>username</name>
                    <value>myusername</value>
                </parameter>
            </ResourceParams>
         </Context>
      </Host>

Code to get connection from pool:

    Context envContext  = (Context)initContext.lookup("java:/comp/env");
    DataSource ds = (DataSource)envContext.lookup("jdbc/orapool");
    return ds.getConnection();


Again, the above configuration works fine when used in a Context under the
"localhost" <Host> element.  It seems to only be when I define another
<Host> element that I get the error.


Any ideas?

Thanks,

Nate


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


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

Reply via email to