Connecting python to DB2 database

DFS nospam at dfs.com
Thu Sep 2 21:38:45 EDT 2021


Having a problem with the DB2 connector

test.py
----------------------------------------------------------------
import ibm_db_dbi
connectstring = 
'DATABASE=xxx;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=xxx;PWD=xxx;'
conn = ibm_db_dbi.connect(connectstring,'','')

curr  = conn.cursor
print(curr)

cSQL = "SELECT * FROM TEST"
curr.execute(cSQL)
rows = curr.fetchall()
print(len(rows))
----------------------------------------------------------------

$python test.py
<ibm_db_dbi.Connection object at 0x000002154D2FED30>
Traceback (most recent call last):
   File "temp.py", line 9, in <module>
     curr.execute(cSQL)
AttributeError: 'function' object has no attribute 'execute'


The ibm_db_dbi library supposedly adheres to PEP 249 (DB-API Spec 2.0), 
but it ain't happening here.


Googling got me nowhere.  Any ideas?

python 3.8.2 on Windows 10
pip install ibm_db


More information about the Python-list mailing list