users@glassfish.java.net

Re: Issue with DataSource lookup in Glassfish

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Jul 2010 13:41:37 PDT

ctx.lookup("java:comp/env/jdbc/MySQLDataSource");

for this to work, you will need to declare a resource-ref in web.xml whose res-ref-name is "jdbc/MySQLDataSource", and is somehow mapped to the jndi-name of the resource you just created. The mapping can be done in sun-web.xml. Any name under java:comp/env namespace is private to your webapp.

Alternatively, you can directly look up the jdbc resource using its jndi-name that you specified when creating this resource, at the expense of flexibility. for example,

lookup("jdbc/MySQLDataSource/world");
[Message sent by forum member 'cf126330']

http://forums.java.net/jive/thread.jspa?messageID=476817