1 Reply Latest reply on Mar 14, 2008 2:47 AM by jaikiran

    JNDI Datasource Lookup not working

    ozguy

      Hi
      I been stuck at this problem and can't seem to see what am doing wrong. I followed the wiki pages for Datasource config and did what it said but i still can't seem to make this work.

      Here is my *-ds.xml file This file is in the default/deploy folder of jboss.


      <local-tx-datasource>
      <jndi-name>questionnaire_DS</jndi-name>
      <connection-url>jdbc:mysql://:3306/questionnaire</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>username</user-name>
      passsword
      <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
      </local-tx-datasource>


      I need to access this in my web application.
      So i have jboss-web.xml as:

      <jboss-web>
      <security-domain flushOnSessionInvalidation="false"/>
      <context-root>/Test</context-root>
      <resource-ref>
      <res-ref-name>jdbc/questionnaire_DS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/questionnaier_DS</jndi-name>
      </resource-ref>
      </jboss-web>

      and in the web.xml I would actually prefer to have this in the context.xml of my web project but that doesn't seem to work either. I used ResourceLink element and it works fine in tomcat but not in jboss.


      <resource-ref>
      Web Questionnaire Datababse connection
      <res-ref-name>jdbc/questionnaire_DS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      My Java class:
      InitialContext ctx = new InitialContext();
      DataSource datasource = (DataSource) ctx.
      lookup("java:comp/env/jdbc/questionnaire_DS");

      This doesn't work.Exception is
      questionnaire_DS is not bound


      java.lang.RuntimeException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: questionnaier_DS not bound]
      com.mishra.TestJndi.init(TestJndi.java:31)
      com.mishra.TestJndi.(TestJndi.java:18)
      org.apache.jsp.hello_jsp._jspService(hello_jsp.java:70)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

      root cause

      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: questionnaier_DS not bound]
      org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1215)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:758)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      javax.naming.InitialContext.lookup(InitialContext.java:392)
      com.mishra.TestJndi.init(TestJndi.java:25)
      com.mishra.TestJndi.(TestJndi.java:18)
      org.apache.jsp.hello_jsp._jspService(hello_jsp.java:70)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

      root cause

      javax.naming.NameNotFoundException: questionnaier_DS not bound
      org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      javax.naming.InitialContext.lookup(InitialContext.java:392)
      org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1209)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:758)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:774)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      javax.naming.InitialContext.lookup(InitialContext.java:392)
      com.mishra.TestJndi.init(TestJndi.java:25)
      com.mishra.TestJndi.(TestJndi.java:18)
      org.apache.jsp.hello_jsp._jspService(hello_jsp.java:70)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

        • 1. Re: JNDI Datasource Lookup not working
          jaikiran

           

          <res-ref-name>jdbc/questionnaire_DS</res-ref-name>


          javax.naming.NameNotFoundException: questionnaier_DS not bound


          Looks like a typo in the lookup string that you are passing. Make sure the spelling is right.