In This Article
Two Reasons to Connect to a Database
To use these Generators and Receivers, GenRocket leverages JDBC.
What is JDBC?
Database Connection Steps
- Step 1 - Create a JDBC Configuration Properties File
- Step 2 - Enter a Value for resource.jdbc.directory Resource
- Step 3 - Download and Place the JDBC connector Jar file into the $GENROCKET_HOME/lib/ folder
- Step 4 - Reference the JDBC Resource in your Generators or Receivers
Step 1 - Create a JDBC Configuration Properties File
A config.properties file is needed for GenRocket to connect to a database via JDBC. GenRocket can connect a 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.
driver=<JDBCDriverClassName> user=<userToConnectToDatabase> password=<passwordToConnectToDatabase> url=<URL>/<databaseName> batchCount=1000
Example config.properties for MySQL database
GenRocket will read this config file and connect to the employee database on localhost using username root and password root.
driver=com.mysql.jdbc.Driver user=root password=root url=jdbc:mysql://localhost:3306/employee?rewriteBatchedStatements=true batchCount=1000
Note: If you are connecting to a different type of database, your configuration file will look different.
Note: It is possible to have more than one config.properties file for different database connections. This requires a little planning and organization, which is further explained here.
Step 2 - Enter a Value for resource.jdbc.directory Resource
An Organization Resource titled resource.jdbc.directory will be automatically available within the GenRocket web platform. It is used to define the primary directory of the config.properties file(s) so that the database connection can be made when querying or inserting data.
This is done via the Organization Resources Pane within the Project Dashboard by using the Edit (Pencil) icon. The resource value is configured per user and should be set to To see step-by-step instructions for changing a resource value, click here.
Example resource.jdbc.directory Configuration
- Set the value of the resource variable to the config file name with the full file path of the directory/folder that contains the config.properties file.
In the example below, the config.properties file is stored on a Windows machine within a subdirectory titled 'databases': C:\Users\april\databases.
Important: After adding the new resource with its value, you will need to update your Profile (in ~/.genrocket folder) on your system. GenRocket will read this resource value from your profile on your system to make a connection with the database.
To learn how to do this, please see one of the following pages:
- Windows: How do I download and set up my profile.grp?
- OSX/Linux: How do I download and set up my Profile.grp?
Step 3 - Download and Place the JDBC connector Jar file into the $GENROCKET_HOME/lib/ folder
- Download and place the appropriate JDBC connector Jar file in your genrocket-3.5.6/lib folder.
- Links are provided below for the following: MySQL, Oracle, and MS SQL.
Note: It is OK if your version doesn't match the one above -- still, just place the MySQL connector in the lib directory.
Microsoft provides the JDBC driver for free. You can download the one that works for your version of SQL Server from one of these links:
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.