4 Replies Latest reply on Nov 14, 2006 4:13 PM by Jerry Gauthier

    JNDI lookup fails with JBoss4.0.4GA Patch1

    Mahesh Santhanam Newbie

      I'm trying to do a JNDI lookup on the DataSource (MySQL) under java: namespace in my JSP and the lookup fails. I've configured all the files pertinent to creating a new data source. I see the new datasource bound in the JNDIView (but not in the global namespace).
      Here's the code:

      <%@ page language="java" %>
      <%@ page import="javax.sql.*,javax.naming.*,java.sql.*" %>
      InitialContext ctxt = new InitialContext();
      DataSource ds = (DataSource) ctxt.lookup("java:/jdbc/MySqlDS");
      Connection con = ds.getConnection();
      if(con != null) out.println("Connection not null");
      else out.println("Connection is null");

      I wanted to set the <use-java-context>false</use-java-context> in the *.ds file but per MySQL its not a good practice for a production environment. How can I circumvent this issue? I want to able to access the data source in a servlet as well as in a POJO.

      Thanx for your help.