This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 and Relational Databases
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: 32481
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32481
    
214

In fact, there is a good example in this thread.
 
Have you checked out Aspose?
 
subject: When we have JNDI address for a jdbc datasource , how we can make connection for it?
 
It's not a secret anymore!