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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NoInitialContextException Using DB2 Data Source and JNDI

Status
Not open for further replies.

theprofessorx

Programmer
Mar 21, 2002
10
US
Hello Developers.

I'm running the following:
- Tomcat 4
- SDK 1.3
- DB2 UDB 7
- Windows NT

I'm trying to configure Tomcat to set up a DB2 data source by using the following (relevant portions of code):

server.xml
<Context path=&quot;/transact&quot; docBase=&quot;transact&quot;
debug=&quot;0&quot; reloadable=&quot;true&quot;>
<Resource name=&quot;jdbc/dbtransact&quot; auth=&quot;Container&quot;
type=&quot;javax.sql.DataSource&quot;/>
<ResourceParams name=&quot;jdbc/dbtransact&quot;>
<parameter>
<name>user</name>
<value>ADMIN</value>
</parameter>
<parameter>
<name>password</name>
<value>itsasecret</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>COM.ibm.db2.jdbc.app.DB2Driver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:db2://localhost:50000/TRANSDB</value>
</parameter>
</ResourceParams>
</Context>

web.xml (of transact application)
<res-ref-name>
jdbc/dbtransact
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>

connect.java
Context ctx = new InitialContext() ;
Context envCtx = (Context) ctx.lookup(&quot;java:comp/env&quot;);
DataSource ds = (DataSource)envCtx.lookup(&quot;jdbc/dbtransact&quot;);
Connection con = ds.getConnection();

When connect.class is run, the following exception is thrown:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial.

I believe this error occurs at ctx.lookup.

Any help, advice, and/or suggestions would be very much appreciated. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top