How to make a connection to a MySQL database with the GenRocket Runtime

You will want to connect to your MySQL database for two reasons: 

  1. To retrieve data from the database while generating data using GenRocket runtime using generators like ListQueryGen, QueryBeforeLoop etc.
  2. To populate tables in the database using receivers like GenericSQLInsertReceiver, MySQLInsertReceiver etc.

To use these Generators and Receivers, GenRocket leverages JDBC.

What is JDBC?

JDBC stands for Java™ database connectivity (JDBC) and is the JavaSoft specification of a standard application programming interface (API) that allows Java programs to access database management systems. GenRocket can connect to any database that supports JDBC. 

Connection Steps 

Step 1: Create a JDBC Configuration Properties File

For GenRocket to connect to a database via JDBC you will need to create a file. A  va application can connect a SQL database via JDBC by reading a JDBC properties file that contains the following information:

  • driver - Defines the name of the specific database driver to use to access the given database.  The actual driver file must be placed in the $GEN_ROCKET_HOME/lib folder on your local computer.
  • user - Defines the Username used to access the database.
  • password - Defines the password used to access the database.
  • url - Defines the specific URL to access the database.
  • batchCount - Defines the number of SQL statements that are batched together and sent to the database for execution.  This property is only mandatory for GenRocket Receivers.


Example for MySQL database

GenRocket will read this config file and connect to employee database on localhost using username root and password root. If you are connecting to a different type of database your configuration file will look different. 


Step 2: Next step is to add a new resource named resource.jdbc.config in the GenRocket Web. 

The resource.jdbc.config resource in this image points to the dev folder. 

  • Set the value of resource variable to the config file name with the full file path.
  • For example, say you have added at location /home/user/Desktop/. Then the resource value will be /home/user/Desktop/
  • Make sure to update your Profile (in ~/.genrocket folder) on your system after adding the new resource with its value. GenRocket will read this resource value from your profile on your system to make a connection with the database. 

Step 3: Download and place the JDBC connector Jar file to the $GENROCKET_HOME/lib/ folder

Step 4: Reference the JDBC Resource in your Generators or Receivers

When you create a Scenario that has a Generator or Receiver that references your jdbc.config resource it will connect directly to your database.