Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36875
481
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36875
481
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, there is a good example in this thread.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!