Database Insertion
This lesson will show how to insert data generated by a single Domain into a Database Table within a Database. For this example, we will be showing how to do this with a MySQL database. However, the same steps can be used to insert data into other databases as well.
Prerequisites:
Steps in Lesson 1 of this Training Module must be completed before completing the steps outlined in this lesson:
- Download the appropriate JDBC driver for the database.
- Create a database connection properties file.
- Add or update the resource.jdbc.directory Organization Resource.
Insert Receivers
GenRocket provides specific Receivers for inserting data into a database. For this example, the MySQLInsertReceiver will be used.
Empty Database Table
For this example, we will be inserting twenty-five user records into a User Table within a MySQL database named user_db. We will be emptying the database table before getting started.
Initial Setup
For this example, a User Domain has been added with four Attributes. The loopCount has been set to 25, and a Scenario has been added to the Domain.
Step 1: Add the Insert Receiver
An Insert Receiver will need to be added to the Domain before data can be inserted into a database. For this example, the MySQLInsertReceiver will be added to the Domain.
Note: For more information on how to add a Receiver to a Domain, click here.
Step 2: Configure the Receiver Parameters
Receiver Parameter changes will need to be made before inserting data into a database. The following Parameters will need to be configured for this example:
- resourceName – Name of the config.properties file.
- databaseName – Name of the database.
- tableName – Name of the database table.
The default values will be used for all other Receiver Parameters in this example. Remember to click the Save button after making any Receiver Parameter changes.
Step 3: Receiver Attributes Property Keys Column Name
The columnName Receiver Attribute Property Key for each Attribute will need to match the actual column name within the database table.
Select the Attributes Property Keys Tab within the Receiver Dashboard to view this information.
The database table column name for the Receiver will default to the same name as the Attribute. This will need to be changed for each Attribute to ensure it matches the actual table column name within the database table.
To do so, complete the following steps for each Receiver Attribute:
-
Click on the first Attribute Name. For this example, the id Attribute is chosen.
-
Then enter a different columnName for the Attribute and click the Save & Next button to move to the next Attribute.
Once finished, the Attributes Property Keys Tab will appear as shown below:
Step 4: Download the Scenario
Next, the user will need to download the Scenario to their local machine. This can be done by clicking on the Download (Cloud) icon within the Project Dashboard or Domain Dashboard.
Step 5: Run the Scenario
On the user’s local machine, open a Command Prompt or Terminal window.
Then make sure the directory matches the path entered for the resource.home.directory within the GenRocket web platform.
Next, enter genrocket -r <ScenarioName.grs>. Replace <ScenarioName.grs> with the actual Scenario File Name. Then press the Enter key.
Database Table Data
As shown below, twenty-five records have been inserted into the User Table within the user_db Database.