6

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?

Community
  • 1
  • 1
user2546624
  • 63
  • 1
  • 1
  • 3

2 Answers2

9

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.

Cristian Meneses
  • 4,013
  • 17
  • 32
  • 5
    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 – user2546624 Jul 03 '13 at 14:35
2

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

<resource-ref name="jdbc/myDS" binding-name="jdbc/myDS" />
Taryn
  • 242,637
  • 56
  • 362
  • 405
maher
  • 21
  • 1