1 2 Previous Next 18 Replies Latest reply: Dec 6, 2012 1:58 AM by Smitha K RSS

javax.naming.NameNotFoundException: jdbc not bound

Dickson Lui Newbie

Hi all,

I want to define an Oracle datasource in JBoss AS 5.0. I follow the steps in the installation guide or even in the article in JBoss.org. I still get the same error.

1. create a oracle-ds.xml in the deploy directory
2. create a jsp inside the web application.

Whenever call this webpage (jsp), get the same error "javax.naming.NameNotFoundException: jdbc not bound".

What's wrong? I double check the xml file without any error. How to trace this problem?

Thanks for any help

  • 1. Re: javax.naming.NameNotFoundException: jdbc not bound
    Peter Johnson Master

    Does this help: http://www.jboss.org/community/wiki/HowDoICreateAResourceRef

    If not, please post the following:
    * oracle-ds.xml file (mainly interested in the jndi-name entry)
    * web.xml file (mainly interested in the resource-ref entry for the database)
    * jboss-web.xml (mainly interested in the resource-ref entry for the database)
    * code that does the lookup

  • 2. Re: javax.naming.NameNotFoundException: jdbc not bound
    Dickson Lui Newbie

    Thanks for Peter's help.

    Refer to the "Setup a Oracle Datasource" article , http://www.jboss.org/community/wiki/SetUpAOracleDatasource,

    Refer to the "DataSource configuration" article ,
    http://www.jboss.org/community/wiki/ConfigDataSources

    Both of these 2 article do not mention that it needs to config "web.xml" and jboss-web.xml".

    About the link to "How do I create a resource-ref?" article, it also does not show how to config for these 2 xml file.

    So stranger, there is no correct document or article to completely guide the end user to setup the data source for a web application to use.

    Dear JBoss,
    Please create a better documentation for using JBoss AS so that any end user won't need to search around to find the usage/method/solution of using JBoss AS.

    Thanks a lot.

  • 3. Re: javax.naming.NameNotFoundException: jdbc not bound
    Peter Johnson Master

    I'm sorry, I didn't look carefully enough at the config files presented in the wiki entry that I referred you to, and did not realize that the information was not relevant for a web app. Here is an example (usually the basic datasource name is the same in all the files, but I used different names so that you can see which names need to be the same):

    *-ds.xml excerpt:

    <jndi-name>jdbc/SomeDS</jndi-name>


    web.xml excerpt:
    <resource-ref>
     <res-ref-name>jdbc/TheDS</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
     <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>


    jboss-web.xml:
    <jboss-web>
     <resource-ref>
     <res-ref-name>jdbc/TheDS</res-ref-name>
     <jndi-name>java:jdbc/SomeDS</jndi-name>
     </resource-ref>
    </jboss-web>
    


    datasource lookup in servlet:
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TheDS");



  • 4. Re: javax.naming.NameNotFoundException: jdbc not bound
    Bob Walker Newbie

    I've been referred here from my own similar query: http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4259203#4259203

    From what I can gather from this thread, a web.xml and jboss-web.xml must exist in the WEB-INF directory of every application that wants to access the globally defined datasource: *.ds.xml.

    It would appear the purpose of the these two files is to map a Java EE Environment Naming Context (enc) 'local' entry (ie java:/comp/env/jdbc/MyDataSource) to a jBossNS 'global' naming entry (ie java:/MyDataSource). Have I got this right?

    Now, is there a way to globally define this mapping for all jBoss web applications in a similar fashion that the *-ds.xml datasource is globally defined? I would like to deliver an application that does not have jBoss specific configuration entries in the web.xml and does not need a jboss-web.xml file.

    I know there are applications (I've installed at least one) that work with jBoss that only need the *-ds.xml deployed. What's the trick?

    Thanks, Bob.

  • 5. Re: javax.naming.NameNotFoundException: jdbc not bound
    Peter Johnson Master

     

    It would appear the purpose of the these two files is to map a Java EE Environment Naming Context (enc) 'local' entry (ie java:/comp/env/jdbc/MyDataSource) to a jBossNS 'global' naming entry (ie java:/MyDataSource). Have I got this right?

    Yes.

    Now, is there a way to globally define this mapping for all jBoss web applications in a similar fashion that the *-ds.xml datasource is globally defined? I would like to deliver an application that does not have jBoss specific configuration entries in the web.xml and does not need a jboss-web.xml file.

    No. The ENC is application-specific. In fact, each web app gets its own ENC. You can verify this by using JNDIView (in the jmx console). And each app can see only its own ENC.

    I know there are applications (I've installed at least one) that work with jBoss that only need the *-ds.xml deployed. What's the trick?

    You can have the app directly look up "java:/MyDatasource" instead of using "jdbc/MyDatasource". In that case you do not need any of the web.xml or jboss-web.xml entries.

  • 6. Re: javax.naming.NameNotFoundException: jdbc not bound
    Bob Walker Newbie

     

    You can have the app directly look up "java:/MyDatasource" instead of using "jdbc/MyDatasource". In that case you do not need any of the web.xml or jboss-web.xml entries.

    I'd already made that change in our source code as a temporary fix. Guess we'll keep it :-)
    Thanks for the quick response.
    Bob.


  • 7. Re: javax.naming.NameNotFoundException: jdbc not bound
    Jack Stevens Newbie

    Hi Peter,

     

    For this:

    jboss-web.xml:

    <jboss-web>

    <resource-ref>

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

    <jndi-name>java:jdbc/SomeDS</jndi-name>

    </resource-ref>

    </jboss-web>

    why wouldn't it be:

    jboss-web.xml:

    <jboss-web>

    <resource-ref>

    <res-ref-name>java:comp/env/jdbc/TheDS</res-ref-name>

    <jndi-name>java:jdbc/SomeDS</jndi-name>

    </resource-ref>

    </jboss-web>

    How does JBoss know to include java:comp/env/ in the <res-ref-name> if we just put <res-ref-name>jdbc/TheDS</res-ref-name>

  • 8. Re: javax.naming.NameNotFoundException: jdbc not bound
    Peter Johnson Master

    Because the ENC is assumed since it is in the context of a web app.

  • 9. Re: javax.naming.NameNotFoundException: jdbc not bound
    Jack Stevens Newbie

    Thanks for the quick response Peter!

     

    For a follow up...

    Say that I have a framework (like Spring) that has another layer of code where you can have a "datasource" bean that essentially holds the jndi name (eg. jdbc/TheDS) in a spring context xml file. Spring converts the jndi name to java:comp/env/jdbc/TheDS in the background.

     

    Would JBoss still see be able to see that the code is using java:comp/env in front of TheDS jndi name even though the java:comp/env is appended in front of TheDS  jndi name only at runtime by Spring used in a class (org.springframework.jdbc.core.JdbcTemplate) found inside a Spring jar.

     

    In other words using a framework like Spring that manages datasources at the application layer can we still successfully map to JBoss's -ds.xml jndi name java:jdbc/SomeDS.

     

    Another answer to a question I would love to know is if this mapping technique can be done only for WARs in JBoss? How about if I just have a bunch of EJBs and/or jars packaged in an EAR file. Is there an EAR equivalent technique to map the jndi names to the JBoss' -ds.xml jndi name.

     

    Again, I appreciate your help!

  • 10. Re: javax.naming.NameNotFoundException: jdbc not bound
    Peter Johnson Master

    I don't use Spring (or rather it has been ages since I did anything with Spring) so I could not comment on that.

     

    As far a EJBs go, I always use the straight JNDI name (java:jdbc/SomeDS in the example). There is no need to translate ENC into the JNDI name.

  • 12. Re: javax.naming.NameNotFoundException: jdbc not bound
    Vikas B Newbie

    Adding this to the *-ds.xml , worked for me......It make your datasource available to the Global JNDI namespace in JBOSS

    <use-java-context>false</use-java-context>

  • 13. Re: javax.naming.NameNotFoundException: jdbc not bound
    madhuripotdar Newbie

    I have made all the necessary configurations to lookup a DB2 datasource on JBboss from a portlet. I am able to lookup that datasource from one portlet successfully.

    However using same configurtions from another portlet, the lookup fails and gives following error -

    java.lang.RuntimeException: javax.naming.NameNotFoundException: jdbc not bound

     

    As it is able to looup the datasource from first portlet, it makes me think that the datasource is configured correctly on server. It is something very obvious missing in other portlet which I am not able to find.I have verified that all the configurations (Entries in jboss-web.xml, web.xml) in other portlet are correct.

     

    Any idea what could be going wrong?

  • 14. Re: javax.naming.NameNotFoundException: jdbc not bound
    Wolf-Dieter Fink Master

    Hi madhuripotdar,

    welcome to the forum. 

     

    For your issue it will be better to open a new thread, describe your problem and add a link to other articles. Often the problems are different.

    Also you should attach you DS configuration and the code how you access the datasource.

     

    regards

    Wolf

1 2 Previous Next