Hello!
I have wrestled with this issue for a few days, now. I have searched the internet, but I can't find any solution.
I use GlassFish 3.1.2.2 and I have set up a new DataSource and Resource for a Derby database. The database works fine. That is, it is possible to ping it from GlassFish. However, when I try to get the DataSource from code, it can't find it.
I can list the JNDI entries from the command line (the __FoodNutritionDB is displayed)
$ asadmin list-jndi-entries --context jdbc
__default: org.glassfish.javaee.services.ResourceProxy
__FoodNutritionDB: org.glassfish.javaee.services.ResourceProxy
__TimerPool: org.glassfish.javaee.services.ResourceProxy
Command list-jndi-entries executed successfully.
but, when I try to get the DataSource from a simple Servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
try {
InitialContext context = new InitialContext();
Object obj = context.lookup("jdbc/__FoodNutritionDB");
writer.println(obj.getClass().toString());
} catch (NamingException e) {
writer.println("Exception: " + e.toString() );
}
finally {
writer.close();
}
}
.. it fail with an exception: Exception: javax.naming.NamingException: Lookup failed for 'jdbc/__FoodNutritionDB' in SerialContext [Root exception is javax.naming.NameNotFoundException: __FoodNutritionDB not found]
The JNDI names jdbc/__default and jdbc/__TimerPool are found with the above code.
I have created the data source via GlassFish Web Console. But, a look at the domain.xml (a part of it), is probably helpful in debugging this issue. See the attached picture.
If anyone could help me with this one, I would be so grateful! Thanks!
Attachment | Size |
---|---|
JNDI-problem.png | 149.16 KB |