Fixed: tomcat/postgres problem

From: "Jason Dinger" <jake451(at)knology(dot)net>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Fixed: tomcat/postgres problem
Date: 2003-04-11 21:24:37
Message-ID: 019101c30070$c1dcb530$2b40ec18@jasonekj7yrm2i
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I fixed my problem. I'm posting my fix in case anyone else runs across this problem.

The problem was that I had the <ResourceParams> in the <GlobalNamingResources> section for a <Resource> I had declared in server.xml. Meanwhile, the Ant install for Tomcat script was installing a <Resource> in the <Context> section based on info in the web.xml file. In short, all I had to do is put the <ResourceParams> in the Context section created by ant install.

If you doubt the "driverClassName is required" error is accurate, you can run this test to see if the driverClassName is really loading.

import javax.naming.NamingEnumeration;
import javax.naming.Binding;
import org.apache.naming.ResourceRef;

NamingEnumeration jdbcEnum = envCtx.listBindings("jdbc"); // envCtx is a Context
while (jdbcEnum.hasMore()) {
Object jdbcObj = jdbcEnum.next();
Binding bind = (Binding)jdbcObj;
writer.println("<p/>***<p/>");
writer.println("ClassName: " + bind.getClassName() + "<br/>");
writer.println("Name: " + bind.getName() + "<br/>");
ResourceRef recRef = (ResourceRef)bind.getObject();
writer.println("Factory Class Name: " + recRef.getFactoryClassName() + "<br/>" + recRef.toString());
writer.println("<p/>***<p/>");
}

You should see something like this:

***

ClassName: org.apache.naming.ResourceRef
Name: MyDB
Factory Class Name: org.apache.naming.factory.ResourceFactory
ResourceRef[className=javax.sql.DataSource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory.ResourceFactory,{type=description,content=Postgresql driver},{type=scope,content=Shareable},{type=auth,content=Container},{type=validationQuery,content=},{type=user,content=myname},{type=password,content=mypassword},{type=maxActive,content=4},{type=maxWait,content=5000},{type=url,content=jdbc:postgresql:mydb},{type=driverClassName,content=org.postgresql.Driver},{type=maxIdle,content=2}]

***

- Jason

a.. From: "Jason Dinger" <jake451(at)knology(dot)net>
b.. To: <pgsql-jdbc(at)postgresql(dot)org>
c.. Subject: tomcat/postgres problem
d.. Date: Wed, 9 Apr 2003 14:40:40 -0500

--------------------------------------------------------------------------------

I'm trying to load the postgresql driver into tomcat using the server.xml file and web.xml file, but I keep getting the following error:

javax.naming.NamingException: DbcpDataSourceFactory: driverClassName is required

Here's part of my server.xml file:

<Resource name="jdbc/MyDB" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MyDB">
<parameter>
<name>validationQuery</name>
<value></value>
</parameter>
<parameter>
<name>user</name>
<value>Jason</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql:mydb</value>
</parameter>
<parameter>
<name>password</name>
<value> </value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>

And here's part of my web.xml file

<resource-ref>
<description>
Postgresql driver
</description>
<res-ref-name>
jdbc/MyDB
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>

I know I can load the driver with Class.forName(). That works too. But how do I get the driver loaded via the server.xml and web.xml files? Any suggestions?

- Jake

Browse pgsql-jdbc by date

  From Date Subject
Next Message David Wall 2003-04-11 23:19:07 Version of driver for 7.3 postgresql
Previous Message George Peiov 2003-04-11 21:17:12 DriverManager.getConnection hangs