aspose file tools*
The moose likes JDBC and the fly likes When we have JNDI address for a jdbc datasource , how we can make connection for it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "When we have JNDI address for a jdbc datasource , how we can make connection for it?" Watch "When we have JNDI address for a jdbc datasource , how we can make connection for it?" New topic
Author

When we have JNDI address for a jdbc datasource , how we can make connection for it?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reading my post.
Imagine that i have a jndi datasource like :
java:comp/env/jdbc/be
now i want to creat a connection from this datasource , how i can do that ?
can you please give me the steps ?
I want to do it in a servlet.

Thanks again.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

Raminaa,
1) Create an initial context. Likely this is as simple as:
InitialContext ctx = new InitialContext(), but it depends on your app server.
2) Get the datasource from the initial context. - lookup by JNDI name
3) Get a connection from the datasource. - getConnection() method.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

In fact, there is a good example in this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When we have JNDI address for a jdbc datasource , how we can make connection for it?