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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JNDI for database" Watch "JNDI for database" New topic
Author

JNDI for database

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
How to use JNDI for database configuration?

Thanks.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

JNDI for database configuration? Not sure what you mean. JNDI is a technology for accessing naming and directory services, not configuring databases. Are you asking about javax.sql.DataSource (i.e. how to get JDBC connection information out of JNDI)?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Medha Jhunjhunwala
Greenhorn

Joined: Sep 06, 2007
Posts: 9
try googling for such kind of things, there are plenty of resources available.
http://www.javapractices.com/Topic127.cjp
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Paul. Yes, I meant that only but being new to JNDI, I couldn't ask that properly.
Thanks Medha, It was nice link and helped me to find more content.

I found a link which explains it step by step: http://www.onjava.com/onjava/2003/01/08/examples/AddressesDB.html.

Code from that article:



But have some doubts:
1. What do we pass into lookup() method? It's a string but mapped to what? and how to map that?
2. Here, this mapping is done in context.xml of tomcat. But what exactly it's mapped to (driver or what?)? It looks like folder path but where it is? What to keep there?
3. What if I am not using tomcat? Where can I provide mapping information?
4. In this example, context.xml again contains the same information like driver name, database string, username and password, then why not use the old method (driver manager one) and keep these information in some properties file?

I searched on net but still have these doubt.

Thanks.
[ September 10, 2007: Message edited by: ankur rathi ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


1. What do we pass into lookup() method? It's a string but mapped to what? and how to map that?

If we are talking about Tomcat here, the binding is done by Tomcat. The Tomcat docs should tell you where it will be bound.


2. Here, this mapping is done in context.xml of tomcat. But what exactly it's mapped to (driver or what?)? It looks like folder path but where it is? What to keep there?

What Tomcat is mapping is a DataSource. It is an address in the JNDI namespace.


3. What if I am not using tomcat? Where can I provide mapping information?

That depends on what naming provider you choose to use. All will have simmilar ways of consiguring DataSource's in JNDI.


4. In this example, context.xml again contains the same information like driver name, database string, username and password, then why not use the old method (driver manager one) and keep these information in some properties file?

Read the JavaDocs for DataSource. The main differences is it can provide connection pooling and distributed transaction support.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Paul.

That depends on what naming provider you choose to use. All will have simmilar ways of consiguring DataSource's in JNDI.


Can you or anyone point me out what naming provider I should use??? and a link which explains how to configure these information into that?

Thanks.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Read this in the Tomcat documentation:
JNDI Datasource HOW-TO

(This is for Tomcat 5.5; if you're using a different version, look it up yourself in the Tomcat documentation).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Jesper Young:
Read this in the Tomcat documentation:
JNDI Datasource HOW-TO

(This is for Tomcat 5.5; if you're using a different version, look it up yourself in the Tomcat documentation).


Hey Jesper, thanks but I am not using tomcat.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

If you are not using Tomcat, then what are you using?

The way you have to configure this depends on your application server. So lookup the documentation of your application server about how to setup a connection pool and how to make it accessible via JNDI.
vijay kiranwithvijay
Greenhorn

Joined: Sep 06, 2007
Posts: 14
http://java.sun.com/products/jndi/overview.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI for database
 
Similar Threads
How do we perform JNDI operation in Ruby
WA #1.....word association
Tomcat not loading mysql database driver
java connect to a hierachical database
J2EE technology would allow the system to interact with the LDAP server?