In Glassfish admin, I setup a JDBC connection pool that I can ping ok. Also in Glassfish admin, I have setup a JNDI JDBC resource called jdbc/myDb
However I'm unable to connect to it from Java. I have tried both injection style:
@Resource (mappedName="jdbc/myDB")
private DataSource datasource;
I have also tried Context style :
Context ctx = new InitialContext();
DataSource datasource = (DataSource)ctx.lookup("jdbc/myDB")
All I get is java.lang.NullPointerException.
I have also tried various naming styles such as java:jdbc/myDB or java:comp/env/jdbc/myDb
This is using the latest Glassfish (4.1), the latest Postgres Driver (9.3-1102 JDBC 41) against Postgres 9.4, and the latest Java (1.8.0_31-b13).