Connecting to IBM Db2 from Domino

Overview


This article describes how to connect to IBM Db2 from Domino.

 

 

 

 

Options for connecting to Db2 from Domino


 

 

 

 

Python and ibm_db2


Domino recommends the ibm_db2 package for interacting with Db2 databases from Python.

 

Environment setup

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

This instruction assumes you already have pip installed.

RUN pip install ibm_db ibm_db_sa

For a basic introduction to modifying Domino environments, watch this tutorial video.

 

Credential setup

There are several environment variables you should set up to store secure information about your Db2 connection. Set the following as Domino environment variables on your user account:

  • db_username
  • db_password

Read Environment variables for secure credential storage to learn more about Domino environment variables. 

 

Usage

Read the ibm_db for detailed information on how to use the package. Below is a simple example for connecting to Db2 with ibm_db where:

  • you have set up environment variables noted above 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

Further reading: IBM database server in Python 

 

 

 

 

R and ibmdbR


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

 

Environment setup

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

RUN R -e 'install.packages("ibmdbR")'

For a basic introduction to modifying Domino environments, watch this tutorial video.

 

Usage

Read the imbdbR documentation for detailed information on how to use the package.

Was this article helpful?
0 out of 0 found this helpful