Sorry the actual code should have read:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myDatasource");
Connection con = ds.getConnection();
(thanks Jagadish) . This code is giving the NameNotFound error.
No object bound to name java:comp/env/jdbc/myDatasource
When I try get the DataSource directly from initContext (as below)
DataSource ds = (DataSource)envContext.lookup("jdbc/myDatasource");
it works.
This makes no sense to me:
in Tomcat there is no problem doing the lookup from envContext.
----- Original Message ----
From: Mon Cab <futon33_at_yahoo.com>
To: users_at_glassfish.dev.java.net
Sent: Monday, March 31, 2008 11:07:57 PM
Subject: NameNotFound exception - makes no sense ?!
This is wierd
I have exacly the same code in two different classes, in the same
package, each getting the same JNDI resource, as follows:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)initContext.lookup("jdbc/myDatasource");
Connection con = ds.getConnection();
The first class is called and gets a connection, with no problem, then
the second class, which uses exaclty the same code to get the
connection gets:
No object bound to name java:comp/env/jdbc/myDatasource
exception.
What is going on here?
____________________________________________________________________________________
Special deal for Yahoo! users & friends - No Cost. Get a month of Blockbuster Total Access now
http://tc.deals.yahoo.com/tc/blockbuster/text3.com
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com