How to connect to a Snowflake Database
There can be two primary reasons for you to make a connection with a Snowflake database with GenRocket:
- 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, SQLUpdateReceiver, etc.
To use these Generators and Receivers, GenRocket leverages JDBC.
In This Article
- What is JDBC?
- Connection Steps
- Step 1: Create a JDBC Configuration Properties File
- Step 2: Enter a valid value for the resource.jdbc.config Organization Resource in GenRocket
- Step 3: Update your Profile in the .genrocket Folder
- Step 4: Download and place the JDBC connector Jar file in the $GENROCKET_HOME/lib/ folder
- Step 5: Reference the JDBC Resource in your Generators or Receivers
- Troubleshooting
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 Snowflake database via JDBC, you must create a config.properties file.
Any application can connect to a Snowflake 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 driver file must be placed in your local computer's $GEN_ROCKET_HOME/lib folder. For Snowflake, the value should be net.snowflake.client.jdbc.SnowflakeDriver.
- 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=net.snowflake.client.jdbc.SnowflakeDriver
user=USER
password=PASSWORD
url=jdbc:snowflake://HOST:PORT/?db=DATABASE_NAME
batchCount=1000
Example Configuration File
GenRocket will read this config file and connect to the employee database on localhost using username root and password root. If you are connecting to a different database, your configuration file will look different.
driver=net.snowflake.client.jdbc.SnowflakeDriver
user=root
password=root
url=jdbc:snowflake://localhost:1521/?db=employee
batchCount=1000
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 config.property 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:
- OSX/Linux: How do I download and set up my profile.grp?
- Windows: How do I download and set up my profile.grp?
Step 4: Download and place the JDBC connector Jar file in the $GENROCKET_HOME/lib/ folder
- Download and place a Snowflake JDBC Connector in your genrocket/lib folder
- For more information on the Snowflake JDBC Connector and download instructions, click here.
Step 5: Reference the JDBC Resource in your Generators or Receivers
When you create a Scenario with a Generator or Receiver that references your jdbc.config resource, it will connect directly to your database.
Troubleshooting
If you cannot connect to your Snowflake database via JDBC, please get in touch with us at support@genrocket.com.