javax.naming.NamingException: Tomcat 6.0 conn to Ora10g

I searched extensively to try and figure out where my error lies, but I am about stumped. I am trying to make a JDBC connection from a web service to an Oracle 10g database using Tomcat 6.0 enabled with Apache AXIS for SOAP implementation. Here is the relevant information:

=== EDMSService.xml (context file in TOMCAT_HOME\webapps\ ) ===

<Contextpath="/EDMSService"

docBase="EDMSService.war"

debug="1"

reloadable="true"

crossContext="true"

useNaming="true">

<Logger className="org.apache.catalina.logger.FileLogger"

prefix="localhost-EDMSService-log."

suffix=".txt"

timestamp="true"/>

<Resourcename="jdbc/EDMS"

auth="Container"

type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/EDMS">

<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>url</name>

<value>jdbc:oracle:thin:@HOST:PORT:DATABASE</value>

</parameter>

<parameter>

<name>username</name>

<value>USERNAME</value>

</parameter>

<parameter>

<name>password</name>

<value>PASSWORD</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>20</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>0</value>

</parameter>

<parameter>

<name>maxWait</name>

<value>60000</value>

</parameter>

<parameter>

<name>removeAbandoned</name>

<value>true</value>

</parameter>

<parameter>

<name>removeAbandonedTimeout</name>

<value>300</value>

</parameter>

</ResourceParams>

</Context>

=== web.xml ===

<resource-ref>

<description>The database for the EDMS Info</description>

<res-ref-name>jdbc/EDMS</res-ref-name>

<res-type>javax.sql.EDMS</res-type>

<res-auth>Container</res-auth>

</resource-ref>

=== java database connection method ===

publicstatic DataSource getDataSource(String connection)throws NamingException

{

DataSource datasource =null;

Context jndi =new InitialContext();

datasource = (DataSource) jndi.lookup("java:comp/env/jdbc/" + connection);

return datasource;

}

=== Libraries in TOMCAT_HOME\lib ===

ojdbc14.jar

classes12.jar

commons-pool-1.3.jar

commons-dbcp-1.2.jar

===

I can locate and pull up the WSDL fine, but when I call a method that accesses the database, I receive the following error:

javax.naming.NamingException: Cannot create resource instance

Any help would be greatly appreciated.

[3578 byte] By [swestenzweiga] at [2007-11-27 5:18:09]
# 1

You're using the Tomcat 5.0/4.x format to configure your resource. It changed from 5.5 onwards.

http://geeklondon.com/blog/view/tipnulljdbc

(I've not used Tomcat 6, but I'm guessing they've improved the error message slightly and that this is essentially the same problem - if not then you've got two issues).

dcmintera at 2007-7-12 10:41:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Thanks for the response, dcminter. I read through the link and followed the advice, modifying my xml file in the CATALINA_HOME\<AppName>\META-INF\ to read the following:

<Contextpath="/EDMSService"

docBase="EDMSService.war"

debug="1"

reloadable="true"

crossContext="true"

useNaming="true">

<Logger className="org.apache.catalina.logger.FileLogger"

prefix="localhost-EDMSService-log."

suffix=".txt"

timestamp="true"/>

<Resourcename="jdbc/EDMS"

auth="Container"

type="javax.sql.DataSource"

username="USERNAME"

password="PASSWORD"

driverClassName="oracle.jdbc.driver.OracleDriver"

url="jdbc:oracle:thin:@HOST:PORT:SID"

/>

</Context>

Unfortunately, that did not change the outcome; I am still receiving the same error.

From what I have read in the Apache documentation for 6.0 (which does provide multiple examples using the outdated syntax), it is no longer necessary to modify the server.xml file in the CATALINA_HOME\conf directory if you place an xml containing the context for the app in the CATALINA_HOME\<AppName>\META-INF\ directory. What it does not indicate is whether this file should be named <AppName>.xml or context.xml?

I am not experiencing the first error reported on the link (java.sql.SQLException: No suitable driver) so I think it is safe to assume my service is able to locate the Oracle JDBC driver.

swestenzweiga at 2007-7-12 10:41:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Ok, I figured it out.

First, you do not need a separate xml file in the project's META-INF\ directory.

You do, however, need to ensure that your CATALINA_HOME\conf\server.xml is updated...correctly. You do need a context path for your app, and it does matter where you put it. The Apache documentation is a bit misleading on this, but if you put your context information right before the </HOST> at the end of the file you should be ok. Do not make my mistake by putting it in the <GlobalNamingResources> area with the other <Resource>. Here is the context I defined:

<Context path="/EDMSService" docBase="EDMSService"

debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/EDMS" auth="Container"

type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"

url="jdbc:oracle:thin:@DATABASE:PORT:SID"

username="USERNAME" password="PASSWORD" maxActive="20" maxIdle="10"

maxWait="-1"/>

</Context>

*Please note that this is for Tomcat 6.0.

I hope this helps someone else. Thanks everyone for the views and/or advice.

swestenzweiga at 2007-7-12 10:41:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

The context.xml in META-INF is an appropriate place to put deployment information and will work. This is the META-INF directory within your application's war file, not a subdirectory of the conf directory. When deployed under Tomcat, the contents of this file will be copied to an appropriate directory under the Tomcat conf directory. For example, $TOMCAT_HOME/conf/localhost/myapp.xml

You can alternatively manually create this file.

Putting the configuration into the server.xml file will work but is deprecated.

(edited).

dcmintera at 2007-7-12 10:41:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...