Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lookup a JDBC DataSource in WebSphere 8.5

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?

like image 686
user2546624 Avatar asked Jul 03 '13 13:07

user2546624


1 Answers

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.

like image 153
Cristian Meneses Avatar answered Sep 28 '22 00:09

Cristian Meneses