Before creating a J2C, you will ususally create a JDBC resource such as a data source or JMS resource such as a connection factory.
- In the WebSphere web console, expand Resources > JDBC or Resoruces > JMS.
- Select a resource.
- Select JAAS - J2C authentication data.
- Select New.
- Give the J2C alias a name and define the username and password. Select OK.
- Select Save.
In this example, a J2C alias for a mySQL data source is created.
On the WebSphere server, the J2C aliases you've created will be in the security.xml file.
Now that you've created the J2C alias, you'll want to configure a data source to use the J2C alias. Select your data source. In the Component-managed authentication alias or Container-managed authentication alias, select the J2C alias you just created and select OK. You would use Component-managed authentication alias if the application using the data source has "Application" as the res-auth policy in the Deployment Descriptor. You would use Container-managed authentication alias if the application using the data source has "Container" as the res-auth policy in the Deployment Descriptor. If the Deployment Descriptor has not specified a res-auth policy, the default is "Application", which means you would only use Container-managed authentication alias when an application has specified "Container" as the res-auth policy.
- Select Save.
- Restart the application server and/or deployment manager.
- Check the data source and select Test connection. You must have the Administrator or Operator role to be able to test conection. If the connection is successful, the following message should be displayed.
Likewise, when an application that is configured to use a data source to make a database connection, the application should be able to connect to the database. For example, let's say there is a Java app that contains markup to connect to a MySQL database.
@Resource(name = "jdbc/mySQL")
When the app resides on WebSphere, the app will know to use the MySQL data source when connecting to the database. In this example, the application is able to connect to the database.
Likewise, at Monitoring and Tuning > Performance Viewer > Current activity > your application server > Summary Reports > JDBC Connection Pools > your JDBC provider > your JNDI, the connection count should be 1 for the single connection to the database.