DB2 with python: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Prerequisites = * Python * Python-dev? = Install = no client software required, just the python module ibm_db sudo pip install ibm_db = Test Connection = ibm_db can s...") |
|||
Line 26: | Line 26: | ||
import ibm_db_dbi | import ibm_db_dbi | ||
conni = ibm_db_dbi.Connection(conn) | conni = ibm_db_dbi.Connection(conn) | ||
conni.tables('SYSCAT', '%') | conni.tables('SYSCAT', '%') | ||
[{'TABLE_SCHEM': 'SYSCAT', 'REMARKS': None, 'TABLE_TYPE': 'VIEW', 'TABLE_NAME': 'ATTRIBUTES', 'TABLE_CAT': None}, ...] | [{'TABLE_SCHEM': 'SYSCAT', 'REMARKS': None, 'TABLE_TYPE': 'VIEW', 'TABLE_NAME': 'ATTRIBUTES', 'TABLE_CAT': None}, ...] |
Revision as of 23:09, 7 December 2015
Prerequisites
- 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}, ...]