DB2 with python: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
= Prerequisites = | = Prerequisites = | ||
I tested python3 | |||
* Python | * Python |
Revision as of 23:11, 7 December 2015
Prerequisites
I tested python3
- Python
- Python-dev?
Install
no client software required, just the python module ibm_db
sudo pip install ibm_db
Test Connection
ibm_db can specify connections by
- referencing db2cli.ini database definitions
- referencing db2dsdriver.cfg definitions
- directly
Example
import ibm_db # conn = ibm_db.connect('alias', 'user', 'pass') conn_str = "DATABASE=mspr;HOSTNAME=job4;PORT=50002;PROTOCOL=TCPIP;UID=db2inst2;PWD=secret;" conn = ibm_db.connect(conn_str, , ) import ibm_db_dbi conni = ibm_db_dbi.Connection(conn) conni.tables('SYSCAT', '%')
[{'TABLE_SCHEM': 'SYSCAT', 'REMARKS': None, 'TABLE_TYPE': 'VIEW', 'TABLE_NAME': 'ATTRIBUTES', 'TABLE_CAT': None}, ...]