# 1安装
pip install ibm_db -i https://pypi.douban.com/simple
安装完,程序里import ibm_db,如果没有报错基本就成功了
但是在真正执行SQL语句的时候,我报错了:SQLCODE=-1042
解决方法:
找到Python目录下的site-packages\clidriver\bin\amd64.VC12.CRT
中找到msvcp120.dll、msvcr120.dll
我用的Anaconda,所以目录在这里:
C:\ProgramData\Anaconda3\Lib\site-packages\clidriver\bin\amd64.VC12.CRT
把msvcp120.dll、msvcr120.dll这两个文件,复制到C:\Windows\System32中即可,再执行成功了。
# 2 运行
import ibm_db_dbi conn = ibm_db_dbi.connect('PORT=50000;PROTOCOL=TCPIP', user='ikas', password='ikasinfo123', host='192.168.12.133', database='ikas', conn_options=None) ''' 192.168.12.133 ikas ikasinfo123 ''' sql1 = "SELECT count(1) FROM DB2_TEST;" cursor = conn.cursor() cursor.execute(sql1) row1 = cursor.fetchall() print(row1)
#[(119890,)]
标签:01,ibm,python,db,dll,cursor,DB2,conn From: https://www.cnblogs.com/alamZ/p/17577362.html