This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI in entry in context.xml and web.xml

 
ani bua
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Then how the flow use to continue . The lookup i use in code taken from where ???
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Check Setting up Tomcat Connection Pool

Regds,
amit
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic