Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within EJB and other Jakarta /Java EE Technologies
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
EJB and other Jakarta /Java EE Technologies
How to get JNDI Service in general class?
avseq anthoy
Ranch Hand
Posts: 108
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want get JNDI Service provided by
Tomcat
, But it can't work.
Are there any wrong in my code that I need to modify?
The code listed as below.
public static void main(String[] args) throws Exception { Connection conn = null; Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory"); Context initContext = new InitialContext(env); Context envContext = (Context) initContext.lookup("java:/comp/env"); DataSource ds = (DataSource) envContext.lookup("jdbc/mydb"); conn = ds.getConnection(); if (conn.isClosed()) System.out.println("Connection close"); else System.out.println("Connection open"); }
My Way,My Pace
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Error while getting Datasource object
Connect DS with JNDI in JBoss AS
Datasource JNDI Lookup in WSAD from standalone app
A question about NoInitialContextException:
mysql connectivity with jboss
More...