You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andy Grove <an...@codefutures.com> on 2004/04/05 12:02:35 UTC
Cannot create JDBC driver of class '' for connect URL 'null'
Hi,
I am trying to convert my Tomcat web application to use JNDI to lookup a
DataSource rather than using DriverManager directly. My application
works fine using DriverManager so I know I have my classpath set up
correctly.
The problem I have seems to be a very common one yet I cannot find a
solution to it using Google. I am getting the following error message
when I attempt to look up a DataSource:
Cannot create JDBC driver of class '' for connect URL 'null'
This implies to me that Tomcat is recognizing my <Resource> declaration
in my conf/server.xml but is not loading the associated
<ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
9 with Sun JDK 1.4.2.
My web.xml contains:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
defining this within the context of my webapp and also in the
GlobalNamingResources section).
<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
/>
<ResourceParams name="jdbc/mydb">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>ebay</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost/mydb</value>
</parameter>
</ResourceParams>
Lastly, my Java code is as follows:
InitialContext initCtx = new InitialContext();
Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
DataSource ds = (DataSource) obj;
return ds.getConnection();
Does anyone have JNDI working with Tomcat? Any help would be much
appreciated!
Thanks,
Andy Grove.
R: Cannot create JDBC driver of class '' for connect URL 'null'
Posted by Ivan Venuti <i....@caribel.pisa.it>.
I had your same problem. I couldn't find any solution but I solved the
problem in this way:
I have set the URL string and the driver name in server.xml as Strings:
<Environment name="ISAS_CS"
type="java.lang.String"
value="jdbc:..." />
<Environment name="ISAS_DN" type="java.lang.String"
value="com.informix.jdbc.IfxDriver" />
and then I use JNDI lookups for them and I create a connection with:
Class.forName(driverName);
conn=DriverManager.getConnection(connectionString);
-- Ivan
-----Messaggio originale-----
Da: Andy Grove [mailto:andy.grove@codefutures.com]
Inviato: lunedì 5 aprile 2004 12.03
A: tomcat-user@jakarta.apache.org
Oggetto: Cannot create JDBC driver of class '' for connect URL 'null'
Hi,
I am trying to convert my Tomcat web application to use JNDI to lookup a
DataSource rather than using DriverManager directly. My application
works fine using DriverManager so I know I have my classpath set up
correctly.
The problem I have seems to be a very common one yet I cannot find a
solution to it using Google. I am getting the following error message
when I attempt to look up a DataSource:
Cannot create JDBC driver of class '' for connect URL 'null'
This implies to me that Tomcat is recognizing my <Resource> declaration
in my conf/server.xml but is not loading the associated
<ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
9 with Sun JDK 1.4.2.
My web.xml contains:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
defining this within the context of my webapp and also in the
GlobalNamingResources section).
<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
/>
<ResourceParams name="jdbc/mydb">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>ebay</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost/mydb</value>
</parameter>
</ResourceParams>
Lastly, my Java code is as follows:
InitialContext initCtx = new InitialContext();
Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
DataSource ds = (DataSource) obj;
return ds.getConnection();
Does anyone have JNDI working with Tomcat? Any help would be much
appreciated!
Thanks,
Andy Grove.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Cannot create JDBC driver of class '' for connect URL 'null'
Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
I'm glad you sorted yourself out Andy.
Just for the record, you *can* define the resource (and its parameters)
within the context of an application - as opposed to making it a global
resource that requires a resource link.
I have it working that way, and I suspect so do many others because this is
the way the Tomcat documents indicate things should be done. See, for
example:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-how
to.html
In that document the resource element is defined as part of a context.
I'm tempted to think that you had something broken in your code, before, and
when you rehashed everything the other way it worked because you got it
right.
IOW it's another way to skin this particular cat (oops!) but not the only
way.
All the best
Harry
> I found the problem.
>
> To get it working I needed to have the <Resource> and <ResourceParams>
> in the Global section and then add a <ResourceLink> in the context for
> my webapp. This enabled Tomcat to resolve the parameters.
>
> I've posted my config files here for anyone interested:
>
> http://www.codefutures.com/weblog/openknowledge/archives/000077.html
>
> On Mon, 2004-04-05 at 15:08, Andy Grove wrote:
>
>> Thanks Harry but the problem is that it is not even trying to load the
>> Postgres driver - it is not getting that far. It is trying to load JDBC
>> driver class '' (empty string) and is trying to access JDBC URL of
>> 'null'. It seems that the ResourceParams section is not being used.
>>
>> I do have the postgres jar deployed to common/lib.
>>
>> Thanks.
>>
>> On Mon, 2004-04-05 at 14:52, Harry Mantheakis wrote:
>>
>>> Hello
>>>
>>>
>>>> My web.xml contains:
>>>
>>>
>>> That looks the same as mine (which works) so no problem there. You do not
>>> actually *need* this element in the deployment descriptor if you are using
>>> Tomcat 5, but it makes your code portable, should you ever (God forbid!)
>>> switch to another servlet container.
>>>
>>>
>>>> My $TOMCAT_HOME/conf/server.xml contains the following...
>>>
>>>
>>> BTW, it is $CATALINA_HOME that matters - $TOMCAT_HOME is not used.
>>>
>>> Looking at your resource definitions, this sub-element:
>>>
>>>
>>> <parameter>
>>> <name>url</name>
>>> <value>
>>> jdbc:postgresql://localhost/mydb
>>> </value>
>>> </parameter>
>>>
>>>
>>> Maybe should read:
>>>
>>>
>>> <parameter>
>>> <name>url</name>
>>> <value>
>>> jdbc:postgresql://localhost:5432/mydb
>>> </value>
>>> </parameter>
>>>
>>>
>>> Mine, at least, needs a port number to be specified.
>>>
>>> The rest of the resource element looks okay to me. Also, your look-up code
>>> looks good too, so my only guess is that you have forgotten to put the
>>> PostgreSQL JDBC driver under the container's classpath.
>>>
>>> You probably have the driver located under your application's 'WEB-INF/lib'
>>> directory.
>>>
>>> Try placing the driver in the '$CATALINA_HOME/common/lib' directory, but do
>>> not have it both places! (Remove it from the 'WEB-INF/lib' directory.)
>>>
>>> Also, make sure you have a driver named 'pg74.1jdbc3.jar'. The one that
>>> comes bundled with the PostgreSQL 7.4 RPM is out of date. You can download
>>> the 7.4 driver from PG's JDBC site.
>>>
>>> Good luck.
>>>
>>> Harry Mantheakis
>>> London, UK
>>>
>>>
>>>
>>>
>>>> Hi,
>>>>
>>>> I am trying to convert my Tomcat web application to use JNDI to lookup a
>>>> DataSource rather than using DriverManager directly. My application
>>>> works fine using DriverManager so I know I have my classpath set up
>>>> correctly.
>>>>
>>>> The problem I have seems to be a very common one yet I cannot find a
>>>> solution to it using Google. I am getting the following error message
>>>> when I attempt to look up a DataSource:
>>>>
>>>> Cannot create JDBC driver of class '' for connect URL 'null'
>>>>
>>>> This implies to me that Tomcat is recognizing my <Resource> declaration
>>>> in my conf/server.xml but is not loading the associated
>>>> <ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
>>>> 9 with Sun JDK 1.4.2.
>>>>
>>>> My web.xml contains:
>>>>
>>>> <resource-ref>
>>>> <description>DB Connection</description>
>>>> <res-ref-name>jdbc/mydb</res-ref-name>
>>>> <res-type>javax.sql.DataSource</res-type>
>>>> <res-auth>Container</res-auth>
>>>> </resource-ref>
>>>>
>>>> My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
>>>> defining this within the context of my webapp and also in the
>>>> GlobalNamingResources section).
>>>>
>>>> <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
>>>> />
>>>>
>>>> <ResourceParams name="jdbc/mydb">
>>>> <parameter>
>>>> <name>factory</name>
>>>> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>maxActive</name>
>>>> <value>100</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>maxIdle</name>
>>>> <value>30</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>maxWait</name>
>>>> <value>10000</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>username</name>
>>>> <value>ebay</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>password</name>
>>>> <value></value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>driverClassName</name>
>>>> <value>org.postgresql.Driver</value>
>>>> </parameter>
>>>> <parameter>
>>>> <name>url</name>
>>>> <value>jdbc:postgresql://localhost/mydb</value>
>>>> </parameter>
>>>> </ResourceParams>
>>>>
>>>> Lastly, my Java code is as follows:
>>>>
>>>> InitialContext initCtx = new InitialContext();
>>>> Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
>>>> DataSource ds = (DataSource) obj;
>>>> return ds.getConnection();
>>>>
>>>> Does anyone have JNDI working with Tomcat? Any help would be much
>>>> appreciated!
>>>>
>>>> Thanks,
>>>>
>>>> Andy Grove.
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Cannot create JDBC driver of class '' for connect URL 'null'
Posted by Andy Grove <an...@codefutures.com>.
I found the problem.
To get it working I needed to have the <Resource> and <ResourceParams>
in the Global section and then add a <ResourceLink> in the context for
my webapp. This enabled Tomcat to resolve the parameters.
I've posted my config files here for anyone interested:
http://www.codefutures.com/weblog/openknowledge/archives/000077.html
On Mon, 2004-04-05 at 15:08, Andy Grove wrote:
> Thanks Harry but the problem is that it is not even trying to load the
> Postgres driver - it is not getting that far. It is trying to load JDBC
> driver class '' (empty string) and is trying to access JDBC URL of
> 'null'. It seems that the ResourceParams section is not being used.
>
> I do have the postgres jar deployed to common/lib.
>
> Thanks.
>
> On Mon, 2004-04-05 at 14:52, Harry Mantheakis wrote:
>
> > Hello
> >
> >
> > > My web.xml contains:
> >
> >
> > That looks the same as mine (which works) so no problem there. You do not
> > actually *need* this element in the deployment descriptor if you are using
> > Tomcat 5, but it makes your code portable, should you ever (God forbid!)
> > switch to another servlet container.
> >
> >
> > > My $TOMCAT_HOME/conf/server.xml contains the following...
> >
> >
> > BTW, it is $CATALINA_HOME that matters - $TOMCAT_HOME is not used.
> >
> > Looking at your resource definitions, this sub-element:
> >
> >
> > <parameter>
> > <name>url</name>
> > <value>
> > jdbc:postgresql://localhost/mydb
> > </value>
> > </parameter>
> >
> >
> > Maybe should read:
> >
> >
> > <parameter>
> > <name>url</name>
> > <value>
> > jdbc:postgresql://localhost:5432/mydb
> > </value>
> > </parameter>
> >
> >
> > Mine, at least, needs a port number to be specified.
> >
> > The rest of the resource element looks okay to me. Also, your look-up code
> > looks good too, so my only guess is that you have forgotten to put the
> > PostgreSQL JDBC driver under the container's classpath.
> >
> > You probably have the driver located under your application's 'WEB-INF/lib'
> > directory.
> >
> > Try placing the driver in the '$CATALINA_HOME/common/lib' directory, but do
> > not have it both places! (Remove it from the 'WEB-INF/lib' directory.)
> >
> > Also, make sure you have a driver named 'pg74.1jdbc3.jar'. The one that
> > comes bundled with the PostgreSQL 7.4 RPM is out of date. You can download
> > the 7.4 driver from PG's JDBC site.
> >
> > Good luck.
> >
> > Harry Mantheakis
> > London, UK
> >
> >
> >
> >
> > > Hi,
> > >
> > > I am trying to convert my Tomcat web application to use JNDI to lookup a
> > > DataSource rather than using DriverManager directly. My application
> > > works fine using DriverManager so I know I have my classpath set up
> > > correctly.
> > >
> > > The problem I have seems to be a very common one yet I cannot find a
> > > solution to it using Google. I am getting the following error message
> > > when I attempt to look up a DataSource:
> > >
> > > Cannot create JDBC driver of class '' for connect URL 'null'
> > >
> > > This implies to me that Tomcat is recognizing my <Resource> declaration
> > > in my conf/server.xml but is not loading the associated
> > > <ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
> > > 9 with Sun JDK 1.4.2.
> > >
> > > My web.xml contains:
> > >
> > > <resource-ref>
> > > <description>DB Connection</description>
> > > <res-ref-name>jdbc/mydb</res-ref-name>
> > > <res-type>javax.sql.DataSource</res-type>
> > > <res-auth>Container</res-auth>
> > > </resource-ref>
> > >
> > > My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
> > > defining this within the context of my webapp and also in the
> > > GlobalNamingResources section).
> > >
> > > <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
> > > />
> > >
> > > <ResourceParams name="jdbc/mydb">
> > > <parameter>
> > > <name>factory</name>
> > > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > > </parameter>
> > > <parameter>
> > > <name>maxActive</name>
> > > <value>100</value>
> > > </parameter>
> > > <parameter>
> > > <name>maxIdle</name>
> > > <value>30</value>
> > > </parameter>
> > > <parameter>
> > > <name>maxWait</name>
> > > <value>10000</value>
> > > </parameter>
> > > <parameter>
> > > <name>username</name>
> > > <value>ebay</value>
> > > </parameter>
> > > <parameter>
> > > <name>password</name>
> > > <value></value>
> > > </parameter>
> > > <parameter>
> > > <name>driverClassName</name>
> > > <value>org.postgresql.Driver</value>
> > > </parameter>
> > > <parameter>
> > > <name>url</name>
> > > <value>jdbc:postgresql://localhost/mydb</value>
> > > </parameter>
> > > </ResourceParams>
> > >
> > > Lastly, my Java code is as follows:
> > >
> > > InitialContext initCtx = new InitialContext();
> > > Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
> > > DataSource ds = (DataSource) obj;
> > > return ds.getConnection();
> > >
> > > Does anyone have JNDI working with Tomcat? Any help would be much
> > > appreciated!
> > >
> > > Thanks,
> > >
> > > Andy Grove.
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
Re: Cannot create JDBC driver of class '' for connect URL 'null'
Posted by Andy Grove <an...@codefutures.com>.
Thanks Harry but the problem is that it is not even trying to load the
Postgres driver - it is not getting that far. It is trying to load JDBC
driver class '' (empty string) and is trying to access JDBC URL of
'null'. It seems that the ResourceParams section is not being used.
I do have the postgres jar deployed to common/lib.
Thanks.
On Mon, 2004-04-05 at 14:52, Harry Mantheakis wrote:
> Hello
>
>
> > My web.xml contains:
>
>
> That looks the same as mine (which works) so no problem there. You do not
> actually *need* this element in the deployment descriptor if you are using
> Tomcat 5, but it makes your code portable, should you ever (God forbid!)
> switch to another servlet container.
>
>
> > My $TOMCAT_HOME/conf/server.xml contains the following...
>
>
> BTW, it is $CATALINA_HOME that matters - $TOMCAT_HOME is not used.
>
> Looking at your resource definitions, this sub-element:
>
>
> <parameter>
> <name>url</name>
> <value>
> jdbc:postgresql://localhost/mydb
> </value>
> </parameter>
>
>
> Maybe should read:
>
>
> <parameter>
> <name>url</name>
> <value>
> jdbc:postgresql://localhost:5432/mydb
> </value>
> </parameter>
>
>
> Mine, at least, needs a port number to be specified.
>
> The rest of the resource element looks okay to me. Also, your look-up code
> looks good too, so my only guess is that you have forgotten to put the
> PostgreSQL JDBC driver under the container's classpath.
>
> You probably have the driver located under your application's 'WEB-INF/lib'
> directory.
>
> Try placing the driver in the '$CATALINA_HOME/common/lib' directory, but do
> not have it both places! (Remove it from the 'WEB-INF/lib' directory.)
>
> Also, make sure you have a driver named 'pg74.1jdbc3.jar'. The one that
> comes bundled with the PostgreSQL 7.4 RPM is out of date. You can download
> the 7.4 driver from PG's JDBC site.
>
> Good luck.
>
> Harry Mantheakis
> London, UK
>
>
>
>
> > Hi,
> >
> > I am trying to convert my Tomcat web application to use JNDI to lookup a
> > DataSource rather than using DriverManager directly. My application
> > works fine using DriverManager so I know I have my classpath set up
> > correctly.
> >
> > The problem I have seems to be a very common one yet I cannot find a
> > solution to it using Google. I am getting the following error message
> > when I attempt to look up a DataSource:
> >
> > Cannot create JDBC driver of class '' for connect URL 'null'
> >
> > This implies to me that Tomcat is recognizing my <Resource> declaration
> > in my conf/server.xml but is not loading the associated
> > <ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
> > 9 with Sun JDK 1.4.2.
> >
> > My web.xml contains:
> >
> > <resource-ref>
> > <description>DB Connection</description>
> > <res-ref-name>jdbc/mydb</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <res-auth>Container</res-auth>
> > </resource-ref>
> >
> > My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
> > defining this within the context of my webapp and also in the
> > GlobalNamingResources section).
> >
> > <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
> > />
> >
> > <ResourceParams name="jdbc/mydb">
> > <parameter>
> > <name>factory</name>
> > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > </parameter>
> > <parameter>
> > <name>maxActive</name>
> > <value>100</value>
> > </parameter>
> > <parameter>
> > <name>maxIdle</name>
> > <value>30</value>
> > </parameter>
> > <parameter>
> > <name>maxWait</name>
> > <value>10000</value>
> > </parameter>
> > <parameter>
> > <name>username</name>
> > <value>ebay</value>
> > </parameter>
> > <parameter>
> > <name>password</name>
> > <value></value>
> > </parameter>
> > <parameter>
> > <name>driverClassName</name>
> > <value>org.postgresql.Driver</value>
> > </parameter>
> > <parameter>
> > <name>url</name>
> > <value>jdbc:postgresql://localhost/mydb</value>
> > </parameter>
> > </ResourceParams>
> >
> > Lastly, my Java code is as follows:
> >
> > InitialContext initCtx = new InitialContext();
> > Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
> > DataSource ds = (DataSource) obj;
> > return ds.getConnection();
> >
> > Does anyone have JNDI working with Tomcat? Any help would be much
> > appreciated!
> >
> > Thanks,
> >
> > Andy Grove.
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
Re: Cannot create JDBC driver of class '' for connect URL 'null'
Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
Hello
> My web.xml contains:
That looks the same as mine (which works) so no problem there. You do not
actually *need* this element in the deployment descriptor if you are using
Tomcat 5, but it makes your code portable, should you ever (God forbid!)
switch to another servlet container.
> My $TOMCAT_HOME/conf/server.xml contains the following...
BTW, it is $CATALINA_HOME that matters - $TOMCAT_HOME is not used.
Looking at your resource definitions, this sub-element:
<parameter>
<name>url</name>
<value>
jdbc:postgresql://localhost/mydb
</value>
</parameter>
Maybe should read:
<parameter>
<name>url</name>
<value>
jdbc:postgresql://localhost:5432/mydb
</value>
</parameter>
Mine, at least, needs a port number to be specified.
The rest of the resource element looks okay to me. Also, your look-up code
looks good too, so my only guess is that you have forgotten to put the
PostgreSQL JDBC driver under the container's classpath.
You probably have the driver located under your application's 'WEB-INF/lib'
directory.
Try placing the driver in the '$CATALINA_HOME/common/lib' directory, but do
not have it both places! (Remove it from the 'WEB-INF/lib' directory.)
Also, make sure you have a driver named 'pg74.1jdbc3.jar'. The one that
comes bundled with the PostgreSQL 7.4 RPM is out of date. You can download
the 7.4 driver from PG's JDBC site.
Good luck.
Harry Mantheakis
London, UK
> Hi,
>
> I am trying to convert my Tomcat web application to use JNDI to lookup a
> DataSource rather than using DriverManager directly. My application
> works fine using DriverManager so I know I have my classpath set up
> correctly.
>
> The problem I have seems to be a very common one yet I cannot find a
> solution to it using Google. I am getting the following error message
> when I attempt to look up a DataSource:
>
> Cannot create JDBC driver of class '' for connect URL 'null'
>
> This implies to me that Tomcat is recognizing my <Resource> declaration
> in my conf/server.xml but is not loading the associated
> <ResourceParams>. I get this problem with Tomcat 4.1 and 5.0 on Red Hat
> 9 with Sun JDK 1.4.2.
>
> My web.xml contains:
>
> <resource-ref>
> <description>DB Connection</description>
> <res-ref-name>jdbc/mydb</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
> My $TOMCAT_HOME/conf/server.xml contains the following (I have tried
> defining this within the context of my webapp and also in the
> GlobalNamingResources section).
>
> <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
> />
>
> <ResourceParams name="jdbc/mydb">
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
> <parameter>
> <name>maxActive</name>
> <value>100</value>
> </parameter>
> <parameter>
> <name>maxIdle</name>
> <value>30</value>
> </parameter>
> <parameter>
> <name>maxWait</name>
> <value>10000</value>
> </parameter>
> <parameter>
> <name>username</name>
> <value>ebay</value>
> </parameter>
> <parameter>
> <name>password</name>
> <value></value>
> </parameter>
> <parameter>
> <name>driverClassName</name>
> <value>org.postgresql.Driver</value>
> </parameter>
> <parameter>
> <name>url</name>
> <value>jdbc:postgresql://localhost/mydb</value>
> </parameter>
> </ResourceParams>
>
> Lastly, my Java code is as follows:
>
> InitialContext initCtx = new InitialContext();
> Object obj = initCtx.lookup( "java:comp/env/jdbc/mydb" );
> DataSource ds = (DataSource) obj;
> return ds.getConnection();
>
> Does anyone have JNDI working with Tomcat? Any help would be much
> appreciated!
>
> Thanks,
>
> Andy Grove.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org