This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes JNDI in entry in context.xml and web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "JNDI in entry in context.xml and web.xml" Watch "JNDI in entry in context.xml and web.xml" New topic
Author

JNDI in entry in context.xml and web.xml

ani bua
Greenhorn

Joined: Mar 06, 2009
Posts: 22
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

Joined: Mar 03, 2008
Posts: 470
Did you have a chance to restart Tomcat after the change?
ani bua
Greenhorn

Joined: Mar 06, 2009
Posts: 22
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

Joined: Mar 06, 2009
Posts: 22
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

Joined: Jun 25, 2001
Posts: 15952
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
ani bua
Greenhorn

Joined: Mar 06, 2009
Posts: 22
Then how the flow use to continue . The lookup i use in code taken from where ???
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hello,
Check Setting up Tomcat Connection Pool

Regds,
amit
 
Don't get me started about those stupid light bulbs.
 
subject: JNDI in entry in context.xml and web.xml
 
Similar Threads
JDBC-CONNECTION POOL
JNDI Driver not found with Derby database connection
Query in : JNDI look up of DataSource
Transaction and Websphere - problems
JNDI problem