Connection Steps For DB2 Database with GenRocket Runtime
- What is JDBC?
- Connection Steps
- Step 1: Download DB2 JDBC Driver and place in the $GENROCKET_HOME/lib/ folder
- Step 2: Create a JDBC Configuration Properties File
- Step 3: Enter a valid value for the resource.jdbc.config Organization Resource in GenRocket
- Step 4: Update your Profile in the .genrocket Folder
- Step 5: Reference the JDBC Resource in your Generators or Receivers
Step 1: Download DB2 JDBC Driver and place
The IBM Data Server Driver for JDBC and SQLJ package includes two JDBC drivers:
- db2jcc.jar - This driver is based on the JDBC 3 specification
- db2jcc4.jar - This driver is based on the JDBC 4 or later specifications
Note: The db2jcc.jar driver is now deprecated. After version 3.72, which is delivered with DB2 Version 11.1 for Linux, UNIX, and Windows Modification Pack 1 Fix Pack 1, db2jcc.jar will include no new features.
Step 2: Create a JDBC Configuration Properties File
For GenRocket to connect to an DB2 database via JDBC you will need to create a config.properties file. Any application can connect a DB2 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. For DB2, the value should be com.ibm.db2.jcc.DB2Driver.
- 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. See more in this information below.
- 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= jdbc:db2://<hostName>:<portNumber>/<databaseName>;<property=value> batchCount=1000
As an example, to connect to a DB2 database named sampledb and is configured to listen in the port 50000 with the user db2admin1 and password P@ssword1, the configuration file would be:
driver= com.ibm.db2.jcc.DB2Driver user=db2admin1 password= P@ssword1 url= jdbc:db2://localhost:50000/sampledb batchCount=1000
JDBC URL Explanation
The general form of the connection URL is jdbc:db2://[hostName[:portNumber]/[databaseName]][;property=value[;property=value]]
- jdbc:db2:// is known as the sub-protocol and is constant.
- hostName is the address of the server to connect to. This could be a DNS or IP address.
- portNumber is the port number of the database instance. The default is 50000.
- databaseName is the name of the datasource.
- Property is one or more option connection properties.