• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1247
  • Last Modified:

difference between datasource,DSN(datasourcename) and JNDI?

Hi, I'm little bit confusing about DSN,JNDI

1. can any body explain the difference between datasource,DSN(datasourcename) and JNDI?
2. can't we to interact with database using DSN?
3. can't we to interact with database using JNDI?
4. where does we can find the JNDI and JNDI tree?
0
murali
Asked:
murali
3 Solutions
 
CEHJCommented:
A DSN is generally used in connection with ODBC and is therefore Windows-specific. JNDI is an implementation of a naming service
0
 
sheltonnCommented:
I think you mean DS (for datasource) instead of DSN.  A datasource is a handle to a data store (almost always a database).  You can get a connection from a database, etc (.getConnection());  A datasource is a resource that is often provided by something else.  That is where JNDI comes in.  JNDI is a tree (usually LDAP) that contains handles to objects.  An example object is a datasource.  You can get a reference to the JNDI tree from the InitialContext.  

try {
    Context ctx = new InitialContext();
    Object obj = ctx.lookup("myDatasource");
} catch (NamingException e) {
    // Handle the error
    System.err.println(e);
}

Connection conn = ((Datasource) obj).getConnection();
0
 
objectsCommented:
> 1. can any body explain the difference between datasource,DSN(datasourcename) and JNDI?

Datasource is a factory for getting database connections.
http://java.sun.com/javase/6/docs/api/javax/sql/DataSource.html
A DSN defines details for making a database connection
http://en.wikipedia.org/wiki/Database_Source_Name 
JNDI is an interface for looking things up (such as a Datasource)
http://mindprod.com/jgloss/jndi.html

> 2. can't we to interact with database using DSN?

Not directly, the DSN defines what you need to create a connection you would then interact with the database using that connection.

> 3. can't we to interact with database using JNDI?

not directly, typically you would lookup your Datasource using JNDI and use it to create a connection.

> 4. where does we can find the JNDI and JNDI tree?

Depends on the implementation you are accessing using JNDI. JNDI itself just defines the interface. for accessing it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now