users@glassfish.java.net

Re: NameNotFound exception - makes no sense ?!

From: Jagadish Prasath Ramu <Jagadish.Ramu_at_Sun.COM>
Date: Tue, 01 Apr 2008 14:30:36 +0530

Lookup of "jdbc/myDatasource" would have worked if there is a
jdbc-resource by that name is available.

Lookup of "java:comp/env/myDataSource" may fail if there is no mapping
available in web.xml, sun-web.xml

Have you specified the resource-ref entries in web.xml, sun-web.xml
correctly ?

https://glassfish.dev.java.net/javaee5/docs/DG/beanr.html
Topic : Mapping References

If the issue still persists, Could you post the "resource-ref" entries
from web.xml and sun-web.xml ?

Thanks,
-Jagadish




On Tue, 2008-04-01 at 00:17 -0700, Mon Cab wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>