Search code examples
jakarta-eewebspherejndi

How to create an web application running on websphere, and which will use the data source provided by websphere?


I'm setting up a web application on websphere, but it can't find the JNDI name of data source provided by webphere.

I'm new to websphere, and haven't used JDNI before, that I found it hard to work on this application directly.

How to create an simple web application which can run on websphere and which uses the data source provided by websphere. Or is there any existing demo I can try?

I think such an application will help me to locate the problem.


Solution

  • If you use a Context lookup, you'll have to declare a new resource reference in the deployment descriptor (web.xml) :

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

    But that's not all. You'll also have to bind this new reference to the server's JDBC resource (ibm-web-bnd.xml) :

    <resource-ref name="jdbc/newReference" binding-name="jdbc/ressourceOnServer"/>
    

    Note that this mechanism is quite similar to what is done on Glassfish with the sun-web.xml file, except that the binding is a little different :

    <resource-ref>
        <res-ref-name>jdbc/newReference</res-ref-name>
        <jndi-name>jdbc/ressourceOnServer</jndi-name>
    </resource-ref>
    

    Look at this question : How do I connect to a Websphere Datasource with a given JNDI name?. If you need more details, I may give an example.