Before creating a J2C, you will probably want to create the data source.
- Select your data source.
- Select JAAS - J2C authentication data.
- Select New.
- Give the J2C alias a name, provide the username and password to connect to the database, and select OK.
- Select Save.
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 JDBC 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 the following markup to connect to a MySQL database.
Connection conn = DriverManager.getConnection("jdbc:mysql://www.example.com:3306/database_name","username","password");
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.