• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI for database

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use JNDI for database configuration?

Thanks.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Medha Jhunjhunwala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try googling for such kind of things, there are plenty of resources available.
http://www.javapractices.com/Topic127.cjp
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic