No, that is absolutely not true and very misleading. The spec actually declares that it should definitely be specified in web.xml no matter what. Tomcat doesn't enforce this, but if you want your webapp to be portable, then you should include it in web.xml. Remember, server.xml is Tomcat's proprietary configuration. J2EE is all about providing a specification for configuration and then allowing proprietary servers to have their own configuration that maps to this and allows it to override it.
The configuration is correct from what I can tell. You might try the following code, though...
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Pool");Not sure if this will fix the problem, but the problem most assuredly is not the issue of having the web.xml config stuff.
Jake
At 10:47 AM 3/31/2003 +0200, you wrote:
Hi,
What is in your web.xml relating to the datasource?
If the datasource is correctly defined in server.xml, there is no need to define it in web.xml, but if you do, web.xml will supersede server.xml, and if web.xml does not have all the correct parameters, you will get this problem.
HTH
-----Original Message----- From: Greg Speechley [mailto:[EMAIL PROTECTED] Sent: 31 March 2003 10:40 To: Tomcat User Subject: Re: JNDI resources
I am trying to use tomcat's DBCP and access it by setting variables in server.xml and web.xml as outlined in the documentation. However it is not getting any of the values that are set in server.xml.
Here is my java code: Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); // Look up our data source DataSource ds = (DataSource) envCtx.lookup("jdbc/Pool"); if (ds != null) { Connection conn = ds.getConnection(); ....... }
However I get the following error: java.sql.SQLException: Cannot load JDBC driver class 'null'. ds is not null but all its variables are (I checked by casting it to BasicDataSource and using the getter methods).
I have the mysql driver in a jar in common/lib and I think I have followed all the steps correctly.
Thanks for your help Greg
PS I am having the same sort of problems with getting the mail variables as well
server.xml ---------------------------------------------------------------------------- ----------- <Server port="8005" shutdown="SHUTDOWN" debug="0"> <!-- Uncomment these entries to enable JMX MBeans support --> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" debug="0"/>
<!-- Global JNDI resources --> <GlobalNamingResources>
<!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"> </Resource> <ResourceParams name="UserDatabase"> <parameter> <name>factory</name> <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value> </parameter> <parameter> <name>pathname</name> <value>conf/tomcat-users.xml</value> </parameter> </ResourceParams>
</GlobalNamingResources> <!-- Define the Tomcat Stand-Alone Service --> <Service name="Tomcat-Standalone">
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8081 --> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="80" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" useURIValidationHack="false" disableUploadTimeout="true" /> <!-- Note : To disable connection timeouts, set connectionTimeout value to -1 -->
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 --> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8009" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="10" debug="0" connectionTimeout="20000" useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
<!-- Define the top level container in our container hierarchy --> <Engine name="Standalone" defaultHost="localhost" debug="0">
<!-- Global logger unless overridden at lower levels --> <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" debug="0" resourceName="UserDatabase"/>
<!-- Define the default virtual host --> <Host name="localhost" debug="0" appBase="webapps" 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="localhost_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="ROOT" debug="0"/> -->
<Context path="/myapp" docBase="myapp" debug="0" reloadable="true" crossContext="true"> <Resource name="mail/Session" auth="Container" type="javax.mail.Session"/> <ResourceParams name="mail/Session"> <parameter> <name>mail.smtp.host</name> <value>mail.learnedsolutions.com</value> </parameter> </ResourceParams>
<Resource name="jdbc/Pool" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/Pool"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter>
<!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. --> <parameter> <name>maxActive</name> <value>100</value> </parameter>
<!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. --> <parameter> <name>maxIdle</name> <value>30</value> </parameter>
<!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. --> <parameter> <name>maxWait</name> <value>10000</value> </parameter>
<!-- MySQL dB username and password for dB connections --> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value>password</value> </parameter>
<!-- Class name for mm.mysql JDBC driver --> <parameter> <name>driverClassName</name> <value>org.gjt.mm.mysql.Driver</value> </parameter>
<!-- The JDBC connection url for connecting to your MySQL dB. The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. --> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value> </parameter> </ResourceParams> </Context> </Host> </Engine> </Service> </Server> ---------------------------------------------------------------------------- -------------------------------- web.xml ---------------------------------------------------------------------------- -------------------------------- <web-app> <servlet> <servlet-name>Hello</servlet-name> <servlet-class>mypackage.Hello</servlet-class> </servlet>
<servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/Hello</url-pattern> </servlet-mapping>
<session-config> <session-timeout>30</session-timeout> <!-- 30 minutes --> </session-config> <resource-ref> <description> Resource reference to a factory for javax.mail.Session instances that may be used for sending electronic mail messages, preconfigured to connect to the appropriate SMTP server. </description> <res-ref-name> mail/Session </res-ref-name> <res-type> javax.mail.Session </res-type> <res-auth> Container </res-auth> </resource-ref> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/Pool</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> ---------------------------------------------------------------------------- -----------------------------
--------------------------------------------------------------------- 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]
