Greetings:
I browsed this forum for related issues but the current answers out there did not seem to resolve my issue. I am new to JNDI and want to use connection pooling in a web app via JNDI and jtds. I know from the Tomcat 5 How-To that there is configuration necessary in the app's web.xml, server.xml and code to retrieve it.
Here's whats in web.xml:
<resource-ref>
<description>Resource reference...</description>
<res-ref-name>jdbc/HER_DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Here's whats in server.xml:
<Resource name="jdbc/HER_DB" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/HER_DB">
<parameter>
<name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://magellan:1433/hera</value>
</parameter>
<parameter>
<name>password</name>
<value>none</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>HER_appUSER</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
Here's the code we use to access the resource:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/HER_DB");
conn = ds.getConnection(com.gocsc.hera.beans.Utilities.NAME,com.gocsc.hera.beans.Utilities.PWD);
When running the application on the web, I run into the following Java Exception:
javax.naming.NamingException: Cannot create resource instance
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:179)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
org.apache.naming.NamingContext.lookup(NamingContext.java:838)
org.apache.naming.NamingContext.lookup(NamingContext.java:185)
org.apache.naming.NamingContext.lookup(NamingContext.java:826)
org.apache.naming.NamingContext.lookup(NamingContext.java:198)
Can anyone see a problem with this configuration that would cause this exception? Any help is much appreciated.
I browsed this forum for related issues but the current answers out there did not seem to resolve my issue. I am new to JNDI and want to use connection pooling in a web app via JNDI and jtds. I know from the Tomcat 5 How-To that there is configuration necessary in the app's web.xml, server.xml and code to retrieve it.
Here's whats in web.xml:
<resource-ref>
<description>Resource reference...</description>
<res-ref-name>jdbc/HER_DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Here's whats in server.xml:
<Resource name="jdbc/HER_DB" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/HER_DB">
<parameter>
<name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://magellan:1433/hera</value>
</parameter>
<parameter>
<name>password</name>
<value>none</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>HER_appUSER</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
Here's the code we use to access the resource:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/HER_DB");
conn = ds.getConnection(com.gocsc.hera.beans.Utilities.NAME,com.gocsc.hera.beans.Utilities.PWD);
When running the application on the web, I run into the following Java Exception:
javax.naming.NamingException: Cannot create resource instance
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:179)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
org.apache.naming.NamingContext.lookup(NamingContext.java:838)
org.apache.naming.NamingContext.lookup(NamingContext.java:185)
org.apache.naming.NamingContext.lookup(NamingContext.java:826)
org.apache.naming.NamingContext.lookup(NamingContext.java:198)
Can anyone see a problem with this configuration that would cause this exception? Any help is much appreciated.