• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNDI in entry in context.xml and web.xml

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am using Data base connection pooling . I am using a JNDi lookup from my code .

I am making the following entry in web.xml
<resource-ref>
<description>My Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Also putting the following entry in the conext.xml

<Resource
auth="Container"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxActive="20"
maxIdle="10"
maxWait="-1"
name="jdbc/TestDB"
password="aa"
type="javax.sql.DataSource"
url="<some db url>"
username="aa"/>

And i am a using the following java code fro accessing the JNDI resource

Context ctx = new InitialContext();
ds =(DataSource) ctx.lookup("java:comp/env/jdbc/TestDB");
conn = ds.getConnection();

Now the problem is if I comment the web.xml entry then the code is still running Then what is the use of putting it in web.xml ???
Thanks in advance.
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you have a chance to restart Tomcat after the change?
 
ani bua
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i have restarted the tomcat but still there is no change.eans if i comment the web.xml entry it is still running.
 
ani bua
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to know how the resource reference in web.xml is reffered to context.xml .Means how are my java code JNDI lookup,web.xml entry and the context entry work togather.If any one can tell me I will be very thankful.It is urgent.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you'll notice, the web.xml entry defines the data type and other J2EE-specific attributes. While Tomcat may be able to get by without the web.xml entry - at least in certain cases - that's no guarantee that all J2EE servers will be able to do so or that future Tomcat releases will be able to do so. For example, Tomcat6 yells at me when I define session objects that aren't serializable, but none of the earlier versions of Tomcat did.
 
ani bua
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then how the flow use to continue . The lookup i use in code taken from where ???
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Check Setting up Tomcat Connection Pool

Regds,
amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic