How to connect to a Postgresql Database

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

  • Reason 1: To retrieve data from the database while generating data using GenRocket runtime using generators like ListQueryGen, QueryBeforeLoop, etc.

  • Reason 2: To populate tables in the database using receivers like GenericSQLInsertReceiver, etc.

To use these Generators and Receivers, GenRocket leverages JDBC.

In This Article

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. An 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 Postgresql database

GenRocket will read this config file and connect to the database using the username and password. 


Step 2: Enter a valid value for the resource.jdbc.config Organization Resource in GenRocket

The resource.jdbc.config Organization Resource specifies the location of the JDBC file on the logged in user's local machine. For more information about Organization Resources, click here.

This resource value should contain the full directory path (e.g., /home/user/dev)

Linux/Mac OSX Example

Windows Example

Step 3: Update your Profile in the .genrocket Folder

Each user has their own Profile that is stored in the .genrocket folder on their local machine. You will need to download and replace your profile (in ~/.genrocket folder) any time the following changes are made: 

  • Resource value(s) are updated
  • A new resource is added
  • A resource is removed

GenRocket will read this resource value from your profile on your system to make a connection with the database. 

To see the complete steps for each Operating System, please see the article below: 

Step 4: Download and place the JDBC connector Jar file in the $GENROCKET_HOME/lib/ folder

Step 5: Test if Genrocket Runtime can connect to your Postgresql Database

  • Go to the folder where is added

  • Open terminal/command prompt in that location

  • Run this command: genrocket -tjdbc

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

When you create a scenario with a Generator or Receiver that references your resource and config file you created, it will connect directly to your database.