python连接DB2

[root@localhost bin]# /usr/local/python2.7.10/bin/easy_install ibm_db2
Searching for ibm-db2
Reading https://pypi.python.org/simple/ibm_db2/
Reading https://pypi.python.org/simple/ibm-db2/
Couldn't find index page for 'ibm_db2' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for ibm-db2
error: Could not find suitable distribution for Requirement.parse('ibm-db2')
[root@localhost bin]# /usr/local/python2.7.10/bin/easy_install ibm_db
Searching for ibm-db
Reading https://pypi.python.org/simple/ibm_db/
Best match: ibm-db 2.0.7
Downloading https://pypi.python.org/packages/54/8a/54857a841cbd485d68f9852dfc16d27b069987a65ade38bb9288471ae98b/ibm_db-2.0.7.tar.gz#md5=08d5071d18b201c7a23249c676f1b84f
Processing ibm_db-2.0.7.tar.gz
Writing /tmp/easy_install-YpY5N7/ibm_db-2.0.7/setup.cfg
Running ibm_db-2.0.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-YpY5N7/ibm_db-2.0.7/egg-dist-tmp-W9wASH
Detected 64-bit Python
Downloading https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz
warning: no files found matching 'README'
warning: no files found matching '*' under directory 'ibm_db_dlls'
In file included from clidriver/include/sqlcli.h:983:0,
                 from clidriver/include/sqlcli1.h:45,
                 from ibm_db.h:15,
                 from ibm_db.c:29:
clidriver/include/sqlext.h:2133:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 RETCODE SQL_API TraceCloseLogFile();            /* Request to close a trace log */
 ^
clidriver/include/sqlext.h:2135:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 DWORD   SQL_API TraceVersion();                 /* Returns trace API version */
 ^
clidriver/include/sqlext.h:2153:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 DWORD SQL_API   ODBCGetTryWaitValue();          /* In Milliseconds(!) */
 ^
In file included from ibm_db.c:29:0:
ibm_db.h:31:0: warning: "PyObject_CheckBuffer" redefined [enabled by default]
 #define PyObject_CheckBuffer  PyObject_CheckReadBuffer
 ^
In file included from /usr/local/python2.7.10/include/python2.7/Python.h:133:0,
                 from ibm_db.c:27:
/usr/local/python2.7.10/include/python2.7/abstract.h:534:0: note: this is the location of the previous definition
 #define PyObject_CheckBuffer(obj) \
 ^
In file included from ibm_db.c:29:0:
ibm_db.c: In function ‘ibm_db_callproc’:
ibm_db.h:54:25: warning: comparison between pointer and integer [enabled by default]
 #define NIL_P(ptr) (ptr == NULL)
                         ^
ibm_db.c:10643:38: note: in expansion of macro ‘NIL_P’
                                 if( !NIL_P(tmp_curr->ivalue ))
                                      ^
ibm_db.c: In function ‘ibm_db_get_last_serial_value’:
ibm_db.c:10866:19: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
             value = ALLOC_N(char,31);
                   ^
ibm_db.c:10845:19: warning: unused variable ‘return_value’ [-Wunused-variable]
         PyObject *return_value = NULL;
                   ^
ibm_db.c:10843:12: warning: unused variable ‘stmt’ [-Wunused-variable]
  PyObject *stmt = NULL;
            ^
ibm_db.c: In function ‘ibm_db_field_nullable’:
ibm_db.c:7104:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
zip_safe flag not set; analyzing archive contents...
testfunctions: module MAY be using inspect.stack
tests: module references __file__
tests.test_000_PrepareDb: module references __file__
tests.test_144_BindParamInsertStmtPARAM_FILE: module references __file__

****************************************
You are downloading a package which includes the Python module for IBM DB2/Informix.  The module is licensed under the Apache License 2.0. The package also includes IBM ODBC and CLI Driver from IBM, which is automatically downloaded as the python module is installed on your system/device. The license agreement to the IBM ODBC and CLI Driver is available in /usr/local/python2.7.10/lib/python2.7/site-packages/clidriver or /usr/local/python2.7.10/lib/python2.7/site-packages/ibm_db-2.0.7-py2.7-linux-x86_64.egg/clidriver.   Check for additional dependencies, which may come with their own license agreement(s). Your use of the components of the package and dependencies constitutes your acceptance of their respective license agreements. If you do not accept the terms of any license agreement(s), then delete the relevant component(s) from your device.
****************************************
creating /usr/local/python2.7.10/lib/python2.7/site-packages/ibm_db-2.0.7-py2.7-linux-x86_64.egg
Extracting ibm_db-2.0.7-py2.7-linux-x86_64.egg to /usr/local/python2.7.10/lib/python2.7/site-packages
Adding ibm-db 2.0.7 to easy-install.pth file

Installed /usr/local/python2.7.10/lib/python2.7/site-packages/ibm_db-2.0.7-py2.7-linux-x86_64.egg
Processing dependencies for ibm-db
Finished processing dependencies for ibm-db
[root@localhost bin]#

[root@localhost bin]# python2.7.10
Python 2.7.10 (default, Sep  1 2015, 21:03:37)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ibm_db import connect
>>> connection = connect('DATABASE=TXDB;' 'HOSTNAME=9.112.82.59;' 'PORT=50000;' 'PROTOCOL=TCPIP;' 'UID=username;' 'PWD=password;', '', '')
>>> uery_str = "SELECT COUNT(*) FROM AP.CTMTCPP"
>>> import ibm_db
>>> uery_str = "SELECT COUNT(*) FROM AP.CTMTCPP"
>>> query_stmt   = ibm_db.prepare(connection, uery_str)
>>> ibm_db.execute(query_stmt)
True
>>>


请使用浏览器的分享功能分享到微信等