You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Mold <da...@yahoo.co.uk> on 2002/09/10 15:44:00 UTC
Unable to use JNDI DataSource
I have now tried this on three different machines with the exact same results:
I am using the admin tool to create a JNDI data source for a MySQL database.
When I try to use the datasource in a servlet, I get the error:
Cannot load JDBC driver class 'null'
I am able to retrieve a org.apache.commons.dbcp.BasicDataSource from the JNDI
with no problem, but all of its fields are empty, including username, password
fields etc, even though these are correctly set in server.xml.
I have all the appropriate jar files in the CATALINA_HOME/common/lib folder. I
am using Tomcat 4.1.10 on Windows 2000 server, with MySQL 3.23. I followed all
the instructions
athttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
very carefully, each time with the same result. I have tried both the mm.mysql
v.2.14 driver and the "new" MySQL Connector/J driver.
I attach the server.xml, web.xml and test servlet I am using. Can anyone throw
any light on what the problem might be? Thank you.
-David
__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
Re: Unable to use JNDI DataSource
Posted by Rosdi bin Kasim <ro...@epantai.com.my>.
Declaring your Datasource in GlobalNamingResources doesn't always work.
What you can do is, either declare the DataSource within your apps Context
itself, like this:
----------------- Option A - Declare the DataSource within your apps
Context ------------------
<Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\tomtest" cookies="true"
path="/tomtest" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
<Resource name="jdbc/test" scope="Shareable" type="javax.sql.DataSource"
auth="Container"/>
<ResourceParams name="jdbc/test">
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test</value>
</parameter>
<parameter>
<name>validationQuery</name>
<value>select * from clients limit 1</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>username</name>
<value>inet</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>password</name>
<value>inet</value>
</parameter>
</ResourceParams>
<Resource name="jdbc/jobsheet" scope="Shareable" type="javax.sql.DataSource"
auth="Container" description="DB Connection"/>
</Context>
-----------------------------------------------
Or, declare it globally as you did, but declare a ResourceLink within your
apps Context, like this:
------------ Option B - Declare a ResourceLink ----------
<Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\tomtest" cookies="true"
path="/tomtest" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
<ResourceLink name="jdbc/test" type="javax.sql.DataSource"
global="jdbc/test"/>
<Resource name="jdbc/jobsheet" scope="Shareable"
type="javax.sql.DataSource" auth="Container" description="DB Connection"/>
</Context>
-------------------------------------------------------------
The problem with option A is, you will have to do that to all your
applications, you cannot share the same config.
The problem with option B is, it does not always work. It works in one of my
machine here, but doesn't work on others.
Good luck!
----- Original Message -----
From: "David Mold" <da...@yahoo.co.uk>
To: <to...@jakarta.apache.org>
Sent: Tuesday, September 10, 2002 9:44 PM
Subject: Unable to use JNDI DataSource
> I have now tried this on three different machines with the exact same
results:
> I am using the admin tool to create a JNDI data source for a MySQL
database.
> When I try to use the datasource in a servlet, I get the error:
> Cannot load JDBC driver class 'null'
>
> I am able to retrieve a org.apache.commons.dbcp.BasicDataSource from the
JNDI
> with no problem, but all of its fields are empty, including username,
password
> fields etc, even though these are correctly set in server.xml.
>
> I have all the appropriate jar files in the CATALINA_HOME/common/lib
folder. I
> am using Tomcat 4.1.10 on Windows 2000 server, with MySQL 3.23. I followed
all
> the instructions
>
athttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-h
owto.html
> very carefully, each time with the same result. I have tried both the
mm.mysql
> v.2.14 driver and the "new" MySQL Connector/J driver.
>
> I attach the server.xml, web.xml and test servlet I am using. Can anyone
throw
> any light on what the problem might be? Thank you.
>
> -David
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
----------------------------------------------------------------------------
----
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app PUBLIC
> "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
> <description>Tomcat Test App</description>
> <servlet>
> <servlet-name>TestServlet</servlet-name>
> <servlet-class>tomtest.TestServlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>TestServlet</servlet-name>
> <url-pattern>/tomtest.svt</url-pattern>
> </servlet-mapping>
> <resource-ref>
> <description>Local DB Connection</description>
> <res-ref-name>jdbc/test</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
----------------------------------------------------------------------------
----
> <?xml version='1.0' encoding='utf-8'?>
> <Server className="org.apache.catalina.core.StandardServer" port="8005"
debug="0" shutdown="SHUTDOWN">
> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
debug="0"/>
> <Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>
> <GlobalNamingResources>
> <Environment name="simpleValue" override="true"
type="java.lang.Integer" value="30"/>
> <Resource name="jdbc/test" scope="Shareable"
type="javax.sql.DataSource" auth="Container"/>
> <Resource name="UserDatabase" scope="Shareable"
type="org.apache.catalina.UserDatabase" auth="Container" description="User
database that can be updated and saved"/>
> <ResourceParams name="jdbc/test">
> <parameter>
> <name>url</name>
> <value>jdbc:mysql://localhost:3306/test</value>
> </parameter>
> <parameter>
> <name>validationQuery</name>
> <value>select * from clients limit 1</value>
> </parameter>
> <parameter>
> <name>maxIdle</name>
> <value>2</value>
> </parameter>
> <parameter>
> <name>maxActive</name>
> <value>4</value>
> </parameter>
> <parameter>
> <name>driverClassName</name>
> <value>com.mysql.jdbc.Driver</value>
> </parameter>
> <parameter>
> <name>maxWait</name>
> <value>5000</value>
> </parameter>
> <parameter>
> <name>username</name>
> <value>inet</value>
> </parameter>
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
> <parameter>
> <name>password</name>
> <value>inet</value>
> </parameter>
> </ResourceParams>
> <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>
> <Service className="org.apache.catalina.core.StandardService" debug="0"
name="Tomcat-Standalone">
> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
redirectPort="8443" bufferSize="2048" port="8080" connectionTimeout="20000"
scheme="http" enableLookups="true" secure="false"
protocolHandlerClassName="org.apache.coyote.http11.Http11Protocol" debug="0"
proxyPort="0" maxProcessors="75" minProcessors="5" tcpNoDelay="true"
acceptCount="10" useURIValidationHack="false">
> <Factory
className="org.apache.catalina.net.DefaultServerSocketFactory"/>
> </Connector>
> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
redirectPort="8443" bufferSize="2048" port="8009" connectionTimeout="20000"
scheme="http" enableLookups="true" secure="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" debug="0"
proxyPort="0" maxProcessors="75" minProcessors="5" tcpNoDelay="true"
acceptCount="10" useURIValidationHack="false">
> <Factory
className="org.apache.catalina.net.DefaultServerSocketFactory"/>
> </Connector>
> <Engine className="org.apache.catalina.core.StandardEngine"
mapperClass="org.apache.catalina.core.StandardEngineMapper" debug="0"
defaultHost="localhost" name="Standalone">
> <Host className="org.apache.catalina.core.StandardHost"
appBase="webapps" liveDeploy="true"
mapperClass="org.apache.catalina.core.StandardHostMapper" autoDeploy="true"
configClass="org.apache.catalina.startup.ContextConfig"
errorReportValveClass="org.apache.catalina.valves.ErrorReportValve"
debug="0" deployXML="true"
contextClass="org.apache.catalina.core.StandardContext" unpackWARs="true"
name="localhost">
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="true" reloadable="true"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="examples"
cookies="true" path="/examples" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> <Logger className="org.apache.catalina.logger.FileLogger"
debug="0" verbosity="1" prefix="localhost_examples_log." directory="logs"
timestamp="true" suffix=".txt"/>
> <Parameter name="context.param.name" override="false"
value="context.param.value"/>
> <Ejb name="ejb/Account" type="Entity" description="Example EJB
Reference" remote="com.mycompany.mypackage.Account"
home="com.mycompany.mypackage.AccountHome"/>
> <Ejb name="ejb/EmplRecord" type="Entity"
remote="com.wombat.empl.EmployeeRecord"
home="com.wombat.empl.EmployeeRecordHome"/>
> <Environment name="maxExemptions" override="true"
type="java.lang.Integer" value="15"/>
> <Environment name="minExemptions" override="true"
type="java.lang.Integer" value="1"/>
> <Environment name="foo/bar/name2" override="true"
type="java.lang.Boolean" value="true"/>
> <Environment name="name3" override="true"
type="java.lang.Integer" value="1"/>
> <Environment name="foo/name4" override="true"
type="java.lang.Integer" value="10"/>
> <Environment name="foo/name1" override="true"
type="java.lang.String" value="value1"/>
> <LocalEjb name="ejb/ProcessOrder"
local="com.mycompany.mypackage.ProcessOrder" type="Session"
description="Example Local EJB Reference"
home="com.mycompany.mypackage.ProcessOrderHome"/>
> <Resource name="mail/Session" scope="Shareable"
type="javax.mail.Session" auth="Container"/>
> <Resource name="jdbc/EmployeeAppDb" scope="Shareable"
type="javax.sql.DataSource" auth="SERVLET"/>
> <ResourceParams name="mail/Session">
> <parameter>
> <name>mail.smtp.host</name>
> <value>localhost</value>
> </parameter>
> </ResourceParams>
> <ResourceParams name="jdbc/EmployeeAppDb">
> <parameter>
> <name>user</name>
> <value>sa</value>
> </parameter>
> <parameter>
> <name>password</name>
> <value></value>
> </parameter>
> <parameter>
> <name>driverName</name>
> <value>jdbc:HypersonicSQL:database</value>
> </parameter>
> <parameter>
> <name>driverClassName</name>
> <value>org.hsql.jdbcDriver</value>
> </parameter>
> </ResourceParams>
> <ResourceLink name="linkToGlobalResource"
type="java.lang.Integer" global="simpleValue"/>
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\webdav" cookies="true" path="/webdav"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\tomcat-docs" cookies="true"
path="/tomcat-docs" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper"
docBase="J:\worklayer" cookies="true" path="/worklayer"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\tomtest" cookies="true"
path="/tomtest" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> <Resource name="jdbc/test" scope="Shareable"
type="javax.sql.DataSource" auth="Container" description="Local DB
Connection"/>
> <Resource name="jdbc/jobsheet" scope="Shareable"
type="javax.sql.DataSource" auth="Container" description="DB Connection"/>
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="true"
displayName="Tomcat Manager Application"
wrapperClass="org.apache.catalina.core.StandardWrapper"
docBase="../server/webapps/manager" cookies="true" path="/manager"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> <ResourceLink name="users"
type="org.apache.catalina.UserDatabase" global="UserDatabase"/>
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="true"
displayName="Tomcat Administration Application"
wrapperClass="org.apache.catalina.core.StandardWrapper"
docBase="../server/webapps/admin" cookies="true" path="/admin"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> <Logger className="org.apache.catalina.logger.FileLogger"
debug="0" verbosity="1" prefix="localhost_admin_log." directory="logs"
timestamp="true" suffix=".txt"/>
> </Context>
> <Context className="org.apache.catalina.core.StandardContext"
crossContext="false" reloadable="false"
mapperClass="org.apache.catalina.core.StandardContextMapper"
useNaming="true" debug="0" swallowOutput="false" privileged="false"
wrapperClass="org.apache.catalina.core.StandardWrapper" docBase="C:\Program
Files\Apache Group\Tomcat 4.1\webapps\ROOT" cookies="true" path=""
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper">
> </Context>
> <Logger className="org.apache.catalina.logger.FileLogger"
debug="0" verbosity="1" prefix="localhost_log." directory="logs"
timestamp="true" suffix=".txt"/>
> </Host>
> <Logger className="org.apache.catalina.logger.FileLogger" debug="0"
verbosity="1" prefix="catalina_log." directory="logs" timestamp="true"
suffix=".txt"/>
> <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="0" resourceName="UserDatabase" validate="true"/>
> </Engine>
> </Service>
> </Server>
>
----------------------------------------------------------------------------
----
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>