Bootstrap FreeKB - IBM WebSphere - Map an application to a JDBC data source during deployment
IBM WebSphere - Map an application to a JDBC data source during deployment

Updated:   |  IBM WebSphere articles

Let's say you have an application that needs to make a connection to a database, such as a mySQL database. In WebSphere, you can create a JDBC data source that points to the mySQL database. Check out my article Create JDBC data source in WebSphere. In this example, the JDBC data source has JNDI "jdbc/mySQL".

 

Optionally, you could also create the J2C authentication alias in WebSphere. The J2C authentication alias would contain the username and password used to connect to the mySQL database. Check out my article JDBC data source and J2C alias in WebSphere.

 

In WEB-INF/web.xml file of your Java applications WAR, you would define the resource reference.

  • res-ref-name should be an exact match of the data source JNDI in WebSphere
  • res-type must be javax.sql.DataSource
<resource-ref>
  <res-ref-name>jdbc/mySQL</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

 

In WEB-INF/ibm-web-bnd.xml of your Java applications WAR.

  • binding-name should be an exact match of res-ref-name
  • name should be an exact match of the data source name in WebSphere
  • authentication-alias is optional - if used, name should be an exact match of the name of the J2C authentication alias in WebSphere
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd 
	xmlns="http://websphere.ibm.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
	version="1.0">

    <resource-ref binding-name="jdbc/mySQL" name="jdbc/mySQL">
      <authentication-alias name="mysql_userid_password"/>
    </resource-ref>

</web-bnd>

 

Now when deploying your application to WebSphere, the application will be set to use the JDBC data source and J2C authentication alias so that the application can connect to the mySQL database.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


February 28 2024 by Asdaq
I think you did a wonderful job. You are doing very well. I found this knowledge as great source of knowledge regarding Websphere in really easy way. Keep it up.

Add a Comment


Please enter a9d7bb in the box below so that we can be sure you are a human.