Connecting db2, at step python2.6:
1, install python2.6 (Note: The current drive is not supported db2 2.7).
2, install setuptools, Download http://pypi.python.org/pypi/setuptools
3, set the environment variable path: increasing the C: \ Python26; C: \ Python26 \ Scripts. I installed the position of, for example, after setuptools installed in the directory C: \ Python26 \ Scripts will generate easy_insatll.exe.
4, the drive installation db2: open cmd window, enter easy_install ibm_db, python searches related packages and installed on python.org.
5, connected db2, and execute the sql statement
# ! / Usr / bin / Python # - * - Coding: UTF-. 8 - * - Import the IBM_DB Conn = ibm_db.connect ( " DATABASE = datebasename; HOSTNAME = 192.168.0.101; PORT = 50000; the PROTOCOL = the TCPIP; the UID = usename ; pwd PWD =; " , " " , " " )
# database name host IP protocol port username password IF conn: SQL = " the SELECT * from TableName " stmt = ibm_db.exec_immediate (conn, SQL) the Result = ibm_db.fetch_both ( stmt) the while (the Result): print "Result :", result[0] result = ibm_db.fetch_both(stmt)
----------------
Disclaimer: This article is CSDN blogger "betry 'original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/betry/article/details/6633209