domino logo
5.0
  • Get started
  • Tech ecosystem
  • Domino Cloud
  • Develop models
  • Work with data
  • Deploy models, apps, launchers
  • Model Monitoring
  • Code Assist
  • Security and credentials
  • Organizations
  • Collaborate
  • Projects
  • Workspaces
  • Environments
  • Executions
  • Additional Resources
  • Domino CLI
  • Troubleshooting
  • Get help
domino logo
About Domino
Domino Data LabKnowledge BaseData Science BlogTraining
>
User Guide
>
Work with data
>
Access external data
>
Data Source connectors
>
Connect to IBM db2

Connect to IBM db2

This topic describes how to connect directly to IBM db2 from Domino. You must have network connectivity between IBM db2 and your Domino deployment.

Warning

Python and ibm_DB2

Domino recommends the ibm_DB2 package for interacting with DB2 databases from Python.

Environment setup

Use the following Dockerfile instruction to add ibm_db to your environment.

This instruction assumes you already have pip installed.

USER root
RUN pip install ibm_db ibm_db_sa
USER ubuntu

Credential setup

Set the following Domino environment variables to store secure information about your DB2 connection.

  • db_username

  • db_password

See Secure Credential Storage to learn more about Domino environment variables.

Usage

See Python support for IBM Db2 for LUW, IBM Informix and IBM Db2 for z/OS for detailed information about how to use the package. The following is an example for connecting to DB2 with ibm_db where:

  • You have set up the environment variables with the db_username and db_password.

  • You’ve replaced my.host.name with the host name for your machine.

import ibm_db
import ibm_db_dbi
import pandas as pd

hostname = 'my.host.name'
port = 50001
username = os.environ['db_username']
password = os.environ['db_password']

def query_db(sql):
 ibm_db_conn = ibm_db.connect("DATABASE=IBMPROD;HOSTNAME={};PORT={};PROTOCOL=TCPIP;UID={};PWD={};".format(hostname, port, username, password), "", "")
 conn = ibm_db_dbi.Connection(ibm_db_conn)

 df = pd.read_sql_query(sql, conn)
 ibm_db.close(ibm_db_conn)
 return df

sql_cmd = """

SELECT
 *
FROM
 table

"""

df_cmd = query_db(sql_cmd)

df_cmd

See Connecting to an IBM database server in Python.

R and ibmdbR

Domino recommends the imbdbR library for interacting with DB2 databases from R.

Environment setup

Use the following Dockerfile instruction to add ibmdbR to your environment.

USER root
RUN R -e 'install.packages("ibmdbR")'
USER ubuntu
Domino Data Lab
Knowledge Base
Data Science Blog
Training
Copyright © 2022 Domino Data Lab. All rights reserved.