Lookup a JDBC DataSource in WebSphere 8.5

19,761

Solution 1

Did you match your web-app defined datasource with a Websphere defined datasource during installation? Websphere usually asks you to bind resources when they are detected on the installation process (If I remember correctly, it is in the step named "Map reference resources to resources").

Other common issue is a Websphere datasource in a different context (Cell/Node/Server) than your app, so it cannot be found at runtime.

Solution 2

You need to add the binding in ibm-web-bnd.xml:

<resource-ref name="jdbc/myDS" binding-name="jdbc/myDS" />
Share:
19,761
user2546624
Author by

user2546624

Updated on June 05, 2022

Comments

  • user2546624
    user2546624 almost 2 years

    I want to use a JDBC Connetion in my webapp which is configured in WebSphere. (Like this one here: How to use JDBC in JavaEE?)

    I had used this DataSource before via JPA but our customer wants to have native SQL ... don't ask.

    I found a lot of examples and tutorial (e.g. http://www.wickcentral.com/java/dl/ds_resreferencesetts_Websphere.pdf, Websphere JNDI lookup fails) but nothing want work.

    The DataSource in the WebSphere has the JNDI-Name "jdbc/myDS"

    I added a resource-ref to my web.xml:

    <resource-ref>
        <res-ref-name>jdbc/myDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
     </resource-ref>
    

    And I tryed to get the DataSource in my Dao:

    ds = (DataSource) new InitialContext()
                    .lookup("java:comp/env/jdbc/myDS");
    

    But what I get is a

     com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [jdbc/myDS], defined for the MyAPP component.
    

    I tryed a lot. Did anyone sees the fault?

  • user2546624
    user2546624 almost 11 years
    Thank you really much. This was the solution. When I develop I deploy the application via eclipse connector. There will be no step like "Map reference resources to resources". If you want to deploy via eclipse connector you need to create a file named ibm-web-bnd.xml in your web-inf folder an add the line <resource-ref name="jdbc/myDS" binding-name="jdbc/myDS" />