File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes database connection from JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "database connection from JNDI" Watch "database connection from JNDI" New topic

database connection from JNDI

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
hi folks,
i always run into the following line of code as far as database connection is concerned from servletcontext:

i never seem to find out where the java:comp/env is defined. can you please explain me whatjava:comp/env is and where it is set up so that we could use it? thanks.
[ April 08, 2003: Message edited by: Himal Chuli ]

Lilac Ezer

Joined: Apr 08, 2003
Posts: 8
java:comp/env is simply the root context for JNDI mappings you declare in your application. If you define a JDBC connection mapped to JNDI name jdbc/myDB, then you can access it through the context java:comp/env/jdbc/myDB. You never need to worry about defining java:comp/env anywhere. Some application servers (like JRun) will not require you to enter java:comp/env when performing a lookup, so check the documentation of your specific J2EE server for more information on JNDI names.
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
thanks for your reply to my concerns which helped me understand relatively better than before. But where and how is the java:comp/env defined so that JNDI recognize it? could i find the place it is defined and change it to something i would like to?
I agree. Here's the link:
subject: database connection from JNDI