Finding a JDBC data source in WebSphere 8.5

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

I used this DataSource before through JPA, but our client wants to have their own SQL ... don't ask.

I found many examples and tutorials (e.g. http://www.wickcentral.com/java/dl/ds_resreferencesetts_Websphere.pdf , Websphere search in JSDI fails ), but nothing needs to work.

WebSphere DataSource has a JNDI name of "jdbc / myDS"

I added the ref resource 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 tried to get a DataSource in my Dao:

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

But I get

  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've tried a lot. Has anyone seen a mistake?

+6
source share
2 answers

Did your data source defined in the web application match this Websphere data source during installation? Websphere usually asks you to link resources when they were discovered during the installation process (if I remember correctly, it is in the step called "Resource Link Resources").

Another common problem is the Websphere data source in a different context (Cell / Node / Server) than your application, so it cannot be found at runtime.

+9
source

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

 <resource-ref name="jdbc/myDS" binding-name="jdbc/myDS" /> 
+2
source

Source: https://habr.com/ru/post/948626/


All Articles