By Katherine Soohoo, Kendrick Ren
With IBM Db2 for z/OS Developer Extension in VS Code, users can create Db2 connection profiles and run SQL against a Db2 system. The SQL statements can exist locally in a file or on z/OS with the help of the Zowe Explorer extension.
The following instructions describe how to run SQL statements on your local machine or on z/OS.
Running SQL on your local machine
The Db2 Developer Extension is required to run SQL statements on your local machine.
1. Install and setup Db2 Developer Extension
- Install Db2 Developer Extension in VS Code.
- Complete the prerequisites for installing Db2 Developer Extension.
- In VS Code's user and workplace settings, specify the extension's settings such as the path to the
db2jcc_license_cisuz.jar
license file, path to the Java installation directory, and the port number used by the Db2 SQL Service.

2. Add a Db2 connection
- Go to the Db2 Developer Extension view by clicking on the icon in the Activity Bar.
- In the CONNECTIONS view, click the plus sign (+) to add a new connection.
- Fill in the connection information and click the Finish button to save the connection profile.
- Upon finishing, an attempt to connect to the profile will be made. If prompted to access keychain, enter the password to allow access.

3. Associate a Db2 connection to a SQL file
This step is required if there is more than one connection profile defined.
- Open a SQL file in VS Code.
- In the Status Bar, click on No Connection and select a connection to associate with the currently opened SQL file.

4. Run the SQL
-
In the editor with the SQL file, right-click to open the context menu and choose Run Options.
-
Specify custom run options, then click the Save button when finished.
-
In the editor with the SQL file, right-click to open the context menu and choose Run All.
Note: To run a subset of SQL statements within the file, highlight the SQL statements you wish to run then right-click and choose Run Selected.
-
If host variables were present in the SQL statements, an additional tab will be revealed to specify the host variables values. After filling in the values, click the Finish button.
-
After the SQL has finished running, the results of the execution will be revealed in another tab. The results of the execution will also be saved in the QUERY HISTORY view of the Db2 Developer Extension view.

Running SQL on z/OS
The features provided by Db2 Developer Extension can also work together with Zowe Explorer extension on the SQL statements which are stored in the data sets or the files in Unix System Service (USS). You can run the SQL statements in the data sets or the USS files in the same way. Zowe Explorer extension is used to access the data sets and the USS files on z/OS.
-
Install Zowe Explorer in VS Code.
-
Go to the Zowe view by clicking on the icon in the Activity Bar.
-
Add a profile under DATA SETS or USS. Refer to the Zowe Explorer Profiles docs for more information.
-
Open the sequential or PDS/PDSE data sets or USS files containing the SQL statements.
Note: The lowest level qualifier of the data sets should be ending with "SQL". If you are using PDS or PDSE data sets, customize files.associations
in settings.json
with the content below.
"files.associations": {
"*.SQL(*).*": "sql"
}
-
Follow the steps in the previous section to create a Db2 connection profile and run SQL with the Db2 Developer Extension.
