Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem Using Tomcat+JNDI+SQL Server

 
Karunakar Kona
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, I am using Tomcat version 5.0.27
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
 
Karunakar Kona
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using com.microsoft.jdbc.sqlserver.SQLServerDataSource for your driver
 
Sudarshan Yadadala
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic