Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JNDI with jTDS 0.8-rc1 and Tomcat 5.0.19

Status
Not open for further replies.

wbrown338

Programmer
Apr 21, 2004
1
US
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.
 
There should be a "Caused by :" or "Root cause :" in the logs - what does that say ? Are you sure you have this jtds thing's jar files in common/lib ?
Why don't you just use MS's driver ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top