Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Problem Using Tomcat+JNDI+SQL Server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, I am using Tomcat version 5.0.27
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you forgot the resource link.
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html#Resource%20Links
 
Karunakar Kona
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using com.microsoft.jdbc.sqlserver.SQLServerDataSource for your driver
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Evil is afoot. But this tiny ad is just an ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic