> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to IBM db2

You can connect to IBM db2 using a Data Source or directly.

## IBM db2 Data Source

Your [administrator must create a Data Source for this data store](/cloud/admin/data-administration/external-data/config-starburst-data-sources#create-a-starburst-jdbc-powered-data-source) for you to use.

After your administrator has created the Data Source, you can work with it in your project as usual.

## Direct connection

Connect directly to [IBM db2](https://www.ibm.com/products/db2) from Domino. You must have network connectivity between IBM db2 and your Domino deployment.

<Warning>
  Domino does not officially support this method. We provide this information as a courtesy.
</Warning>

## Python and ibm\_DB2

Domino recommends the [ibm\_DB2](https://www.ibm.com/support/knowledgecenter/bg/SSEPGG_9.7.0/com.ibm.swg.im.dbclient.python.doc/doc/t0054368.html) package for interacting with DB2 databases from Python.

### Environment setup

Use the following Dockerfile instruction to add [ibm\_db](https://pypi.org/project/ibm_db/) to your environment.

This instruction assumes you already have [pip](https://pypi.org/project/pip/) installed.

```dockerfile theme={null}
RUN pip install ibm_db ibm_db_sa
```

### Credential setup

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

* `db_username`

* `db_password`

See [Store Project credentials](/cloud/platform-capabilities/core-concepts/projects/configure-projects/store-project-credentials) to learn more about Domino environment variables.

### Usage

See [Python support for IBM Db2 for LUW, IBM Informix and IBM Db2 for z/OS](https://github.com/ibmdb/python-ibmdb) 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.

```python theme={null}
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](https://www.ibm.com/support/knowledgecenter/bg/SSEPGG_9.7.0/com.ibm.swg.im.dbclient.python.doc/doc/t0054368.html).

## R and ibmdbR

Domino recommends the [imbdbR](https://www.ibm.com/support/knowledgecenter/en/SS6NHC/com.ibm.swg.im.dashdb.doc/connecting/connect_connecting_rstudio.html) library for interacting with DB2 databases from R.

### Environment setup

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

```dockerfile theme={null}
RUN R -e 'install.packages("ibmdbR")'
```

## Next steps

* After connecting to your Data Source, learn how to [Use Data Sources](/cloud/platform-capabilities/core-concepts/data/data-source-connectors/use-data-sources).

* [Share this Data Source](/cloud/platform-capabilities/core-concepts/data/sharing-and-security/share-data-sources) with your collaborators.
