Using Glassfish v2, I'm playing with Java EE development. I'm writing a servlet that accesses a PostreSQL database. In the admin console I have the connection pool setup and pings succeed.
When I try to get to the JDBC resource through JNDI it doesn't show up. I have the JDBC Resource set up as:
JNDI Name: jdbc/bang/readOnly
Pool Name: BangReadOnly
Description a read only connection to the Bang database.
Status: Enabled
web.xml has:
<resource-ref>
<description>Connection to the Bang database for reading.</description>
<res-ref-name>jdbc/bang/readonly</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
sun-web.xml has:
<resource-ref>
<res-ref-name>jdbc/bang/readonly</res-ref-name>
<jndi-name>jdbc/bang/readOnly</jndi-name>
</resource-ref>
In the processRequest method I have the following code to get the JNDI context:
try {
Context context = new InitialContext();
Hashtable<?, ?> environment = context.getEnvironment();
Object lookup = context.lookup("java:comp/env/jdbc/bang/readonly");
lookup.toString();
} catch (NamingException ex) {
Logger.getLogger(Data.class.getName()).log(Level.SEVERE, null, ex);
}
I'm certain whatever I'm missing is rather simple. I would greatly appreciate it if someone could explain why I can't get the JDBC resource in the JNDI context and how to fix it.
Thanks.
[Message sent by forum member 'diltsman' (diltsman)]
http://forums.java.net/jive/thread.jspa?messageID=280286