2 Replies Latest reply on Feb 11, 2003 9:36 AM by Beppe

    ANSWER: JNDI and Datasource and EJB issue

    Jeff Andrews Newbie

      I've seen a lot of postings regarding using the
      j2ee ENC naming context to get to a datasource. With
      much chagrin I've never seen it answered completely or
      with example. I'm posting this just because I haven't
      seen it in these forums, not to say that it hasn't been

      Take a Product session bean. Inside the bean impl, a
      need to connect to the data source is required. I need
      to make sure my jboss.xml references the resource and
      I must have a matching resource ref in the ejb-jar.xml

      This would be in the ejb-jar.xml





      This would be in the jboss.xml


      Within the bean impl I can do this:
      Context ctx = new InitialContext();
      Context tmp =
      DataSource ds =

      Connection conn = ds.getConnection();

      And with that I have my connection.

      Hope this helps you with the jndi enc issue.