Connect to DB2 Data Using the Script Function in Claris FileMaker Pro



Use the CData ODBC Driver for IBM DB2 and the Script function in FileMaker Pro to connect to DB2 and work with DB2 data in your FileMaker application.

Claris FileMaker is a low-code database application development tool that enables users to create custom apps for managing and organizing data. It combines a powerful relational database engine with an intuitive interface, allowing both technical and non-technical users to design and deploy applications across desktop, web, and mobile platforms.

In this article, we'll explore how to use the CData ODBC Driver for IBM DB2 and FileMaker scripting to connect to DB2 data.

Create an ODBC Data Source for DB2

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

Set the following properties to connect to DB2:

  • Server: Set this to the name of the server running DB2.
  • Port: Set this to the port the DB2 server is listening on.
  • Database: Set this to the name of the DB2 database.
  • User: Set this to the username of a user allowed to access the database.
  • Password: Set this to the password of a user allowed to access the database.

You will also need to install the corresponding DB2 driver:

  • Windows: Install the IBM Data Server Provider for .NET.

    On Windows, installing the IBM Data Server Provider is sufficient, as the installation registers it in the machine.config.

  • Java: Install the IBM Data Server Driver for JDBC.

    In the Java version, place the IBM Data Server Driver JAR in the www\WEB-INF\lib\ folder for this application.

When you configure the DSN, you may also want to set the Max Rows connection property. This will limit the number of rows returned, which is especially helpful for improving performance when designing reports and visualizations.

Connect and Sync DB2 data with FileMaker Using Scripts

In this section, we walk through the steps to connect live DB2 data to FileMaker using the CData ODBC Driver for IBM DB2 and the Script function. During the initial import, FileMaker brings in all data from the external data source. From the second import onward, it updates only the data that has changed in the external source (a differential update). You can also replace the data in the current record order and schedule these differential updates for automated syncing.

You can download and install the latest version of FileMaker Pro for your Mac/Windows/Linux systems from this link.

Connect and sync DB2 data with FileMaker using scripts

Scripting in FileMaker automates complex tasks and workflows by running a sequence of actions with a single command. By using scripting to integrate with DB2, you can automatically connect to, import, update, and replace DB2 data within your FileMaker applications, streamlining data management and improving efficiency.

First-time importing and adding DB2 data using script

In this section, we'll use scripts to import DB2 data into FileMaker by following these steps:

  1. Open FileMaker Pro. Navigate to Create from the left panel and select Blank > Create.
  2. Enter a filename of your choice and click Save.
  3. In the Manage Database window, go to the Tables tab and create or rename the table where you want to display the DB2 data.
  4. In the Fields tab, create and add the fields you want to use in the table.
  5. In the Relationships tab, add table relationships if there are multiple tables, then click OK.
  6. To reopen and modify the table structure, go to File > Manage > Database.
  7. Navigate to Scripts > Script Workspace.
  8. Select New Script to open a new script workspace.
  9. From the Steps panel on the right, select Records > Import Records > Insert into Script.
  10. In the Specify Data Source dropdown, choose ODBC Data.
  11. Select CData DB2 Sys from the Select ODBC Data Source window, and click Continue. Enter your DB2 credentials and click OK.
  12. In the Specify ODBC SQL Query dialog, enter the SQL query in the SQL text editor to import the desired DB2 data.
  13. Alternatively, select Query Builder to open the SQL Query Builder window. Choose the target table from the Tables section and relevant columns from the Columns section. Click Insert into SQL Query after each selection to auto-generate the query. You can also manually edit the query using WHERE and ORDER BY clauses or the designated tabs. Click OK to finalize the query.
  14. Click OK.
  15. In the Specify import order option, click Specify and enter the DB2 credentials.
  16. In the Specify Import Order window, define the import order for the target fields you added earlier. Select Add between the source and target fields to insert the DB2 data as new records in the table. Click Import.
  17. The script now appears in the workspace. Click Run to execute the script and process the import.
  18. FileMaker imports the DB2 data as a table.

Update or Replace Imported DB2 data Using a Script

After importing the DB2 data into FileMaker, use scripts to update or replace any changes made in DB2 by following this process:

  1. Go back to the Script Workspace by following the steps mentioned in the earlier section.
  2. Select the existing script, click the settings button, choose Specify under Specify Import Order, and re-enter the DB2 credentials to authenticate.
  3. In the Specify Import Order window, choose Update between source and target to update the imported DB2 data. This updates the target's found set with DB2 data values from selected fields when the match fields have the same values. You must define at least one match field in the mapping and select the checkbox Add remaining data as new records. Click Import.
  4. Alternatively, choose the Replace option instead of Update, based on your use case. This replaces the selected fields in the target's found set with DB2 data in the current record order. Click Import.
  5. FileMaker adds the script to the workspace. Click Run to execute the script and process the import query.
  6. FileMaker imports the updated or replaced DB2 data as a table.

Get Started Today

Download a free 30-day trial of CData ODBC Driver for IBM DB2 to integrate DB2 data into Claris FileMaker and work with DB2 data in your FileMaker applications.

Reach out to our Support Team if you have any questions.

Ready to get started?

Download a free trial of the IBM DB2 ODBC Driver to get started:

 Download Now

Learn more:

IBM DB2 Icon IBM DB2 ODBC Driver

The IBM DB2 ODBC Driver is a powerful tool that allows you to connect with live data from IBM DB2, directly from any applications that support ODBC connectivity.

Access IBM DB2 data like you would a database - read, write, and update through a standard ODBC Driver interface.