aspose file tools*
The moose likes Tomcat and the fly likes Problem Using Tomcat+JNDI+SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Problem Using Tomcat+JNDI+SQL Server" Watch "Problem Using Tomcat+JNDI+SQL Server" New topic
Author

Problem Using Tomcat+JNDI+SQL Server

Karunakar Kona
Greenhorn

Joined: Oct 12, 2004
Posts: 4
Hi,

I am a newbie to Tomcat and am having this problem with configuring Tomcat to use SQL Server 2000 thru JNDI.I am getting a NoInitialContextException.

javax.naming.NoInitialContextException: Need to specify class name in environment or system properly,or as an applet parameter, or in an application resource file:java.naming.factory.initial

at javax.naming.spi.Namingmanager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.initialContext.lookup(Unknown Source)
at AppLogin.jButton1ActionPerformed(AppLogin.java)


Here is the code I have done..

server.xml

-----------------------------
<GlobalNamingResources>
<Environment name="jdbc/sqlserver" type="javax.sql.DataSource"/>

<Resource name="jdbc/sqlserver" auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/sqlserver">

<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost/Genesis_ProtoType</value>
</parameter>
<parameter>
<name>username</name>
<value>kona</value>
</parameter>
<parameter>
<name>password</name>
<value>kona</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
------------------------------

web.xml of my application has the following code

<resource-ref>
<res-ref-name> jdbc/sqlserver</res-ref-name>
<res-type> javax.sql.DataSource</res-type>
<res-auth> Container</res-auth>
</resource-ref>
--------------------------------------------------------
My application code:

String sConStr = "java:comp/env";
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(sConStr); --->problem

DataSource ds = (DataSource)envCtx.lookup("jdbc/sqlserver");

----------------------------------------------------------
Lookin at the exception I think I am missing a link somewhere.
Can anyone point me in the right direction?

thanks,
Karunakar Kona
Karunakar Kona
Greenhorn

Joined: Oct 12, 2004
Posts: 4
BTW, I am using Tomcat version 5.0.27
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

you forgot the resource link.
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html#Resource%20Links
Karunakar Kona
Greenhorn

Joined: Oct 12, 2004
Posts: 4
Mike,
Thanks for the reply.

I added the ref-link in ROOT\WEB-INF\web.xml as

<ResourceLink name="linkTosqlserver"
global="jdbc/sqlserver"
type="javax.sql.DataSource">
</ResourceLink>

and changed the code in my app to look up the data source to

DataSource ds = (DataSource)envCtx.lookup("linkTosqlserver");

Now I am ending with the following exception..

javax.naming.NameNotFoundException: Name linkTosqlserver is not found in this Context

All my servlets are in a package/directory in ROOT\WEB-INF\classes.
Am I missing something else somewhere?

thanks,
Karunakar Kona
Gerard kavanagh
Greenhorn

Joined: Oct 28, 2004
Posts: 2
Try using com.microsoft.jdbc.sqlserver.SQLServerDataSource for your driver
Sudarshan Yadadala
Greenhorn

Joined: Dec 09, 2009
Posts: 1
Exception -- 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 am also getting above error, please advise me what to do?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Using Tomcat+JNDI+SQL Server