There are many ways with which AEM enables integration with external database. One of the most common & standard practice of database integration is by using Apache Sling Connection Pooled DataSource configuration properties through the configMgr.
The first step is to download and deploy the appropriate MySQL drivers to AEM.
Then set the Sling Connection Pooled DataSource properties specific to your database. The following screenshot shows the settings used for this tutorial. The database schema is provided to you as part of this tutorial assets.
Please make sure you name your datasource
StoreAndRetrieveAfData as this is the name used in the OSGi service.
The following database was used for the purpose of this use case. The database has one table called
formdatawithattachments with the 4 columns as shown in the screen-shot below.
Please create the database by importing the database schema
using MySQL workbench.
Create form data model and base it on the datasource created in the previous step.
Configure the get service of this form data model as shown in the screen shot below.
Make sure you are not returning array in the get service.
This get service is used to fetch the telephone number associated with the application id.
This form data model will then be used in the MyAccountForm to fetch the telephone number associated with the application id.