Python Uses ibm_db connect to DB2
安裝好了Python和ibm_db以後,做了幾個小例子測試一下
>>> import ibm_db
>>> ibm_db.__version__
'2.0.9'
>>>
=======================================================================
#!/usr/bin/python
#Example 1: Connect to a local or cataloged database
import ibm_db
conn = ibm_db.connect( "dsn=SAMPLE", "db2inst1", "dbpwd" )
sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"
stmt = ibm_db.exec_immediate(conn, sql)
dictionary = ibm_db.fetch_both(stmt)
while dictionary != False:
print(dictionary["QUOTEID"])
print(dictionary["GEO"])
dictionary = ibm_db.fetch_both(stmt)
=======================================================================
#!/usr/bin/python
Example 2: Connect to an uncataloged database
import ibm_db
conn = ibm_db.connect("DATABASE=SAMPLE;HOSTNAME=192.168.101.133;PORT=60006;PROTOCOL=TCPIP;UID=db2inst1;PWD=dbpwd;", "", "")
sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"
stmt = ibm_db.exec_immediate(conn, sql)
dictionary = ibm_db.fetch_both(stmt)
while dictionary != False:
print(dictionary["QUOTEID"])
print(dictionary["GEO"])
dictionary = ibm_db.fetch_both(stmt)
=========================================================================
#!/usr/bin/python
#Example 3: Connect to an uncataloged database with SSL enabled
import ibm_db
conn = ibm_db.connect("DATABASE=SAMPLE;HOSTNAME=192.168.101.133;PORT=50001;SECURITY=SSL;UID=db2inst1;PWD=dbpwd;SSLServerCertificate=/home/db2inst1/db2_ssl/db2_ssl_keydb.arm;", "", "")
sql = "SELECT QUOTEID,GEO FROM DB2INST1.TRN fetch first 10 rows only with ur"
stmt = ibm_db.exec_immediate(conn, sql)
dictionary = ibm_db.fetch_both(stmt)
while dictionary != False:
print(dictionary["QUOTEID"])
print(dictionary["GEO"])
dictionary = ibm_db.fetch_both(stmt)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/725820/viewspace-2216026/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DB2 connect to database連線資料包錯DB2Database
- Android 中 uses-feature 和 uses-permission的作用 關係和區別Android
- How Oracle Uses the Data Dictionary (262)Oracle
- Uses of Function-Based Indexes (200)FunctionIndex
- Python connect zookeeper use the kazoo modulePython
- db2 連線報錯connect。 ERRORCODE=-4499, SQLSTATE=08001DB2ErrorSQL
- Oracle connect byOracle
- start with ... connect by
- DB2:ksh: db2: not found.DB2
- These common uses of distributed transactions have pits, let's see the correct posture
- Laravel connect oracleLaravelOracle
- database的connectDatabase
- start with connect by prior
- start with connect by 用法
- Oracle “CONNECT BY” 使用Oracle
- session,connect,processSession
- oracle connect by用法Oracle
- Oracle Start with ....Connect ByOracle
- START WITH...CONNECT BY
- DB2系列之DB2安裝DB2
- [DB2]DB2備份和恢復DB2
- [DB2]db2重定向恢復DB2
- connect by層內排序排序
- JDBC connect SCAN IPJDBC
- MySQL-undefinedfunctionmysql_connect()MySqlUndefinedFunction
- START WITH and CONNECT BY in Oracle SQLOracleSQL
- connect by..start with..
- mysql connect speed is slowMySql
- start with ...connect by --轉載
- connect your tunnel to CloudflareCloud
- QObject::connect()函式Object函式
- 【CONNECT BY】使用connect by level/rownum實現連續數字的插入
- PostgreSQLOracle相容性之-connectby高階選項CONNECT_BY_ISLEAF、SYS_CONNECT_BY_PATH、CONNECT_BY_ISCYCLE、LEVELSQLOracle
- DB2 WLMDB2
- DB2 explainDB2AI
- DB2 listenerDB2
- db2概念DB2
- DB2 INFOCENTERDB2