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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python connect zookeeper use the kazoo modulePython
- These common uses of distributed transactions have pits, let's see the correct posture
- DB2 WLMDB2
- Laravel connect oracleLaravelOracle
- database的connectDatabase
- db2 -attribute of key are miss in result set . db2 錯誤DB2
- INBOUND_CONNECT_TIMEOUT與SQLNET.INBOUND_CONNECT_TIMEOUT小結SQL
- 使用SockJS 報錯 Incompatibile SockJS! Main site uses: “1.0.3“, the iframe: “1.0.0“. 已處理JSAI
- db2 reorg,runstatsDB2
- DB2的STMTIDDB2
- Db2 備份DB2
- DB2 安裝DB2
- CocoaAsyncSocket---Connect (下)
- QObject::connect()函式Object函式
- connect by層內排序排序
- connect your tunnel to CloudflareCloud
- DB2 SQL改寫DB2SQL
- DB2 HADR效能分析DB2
- The Db2 Recovery History FileDB2
- db2 load dumpfile for exceptionDB2Exception
- Oracle連線Db2OracleDB2
- 常用的DB2命令DB2
- DB2 export詳解DB2Export
- db2 資料庫DB2資料庫
- db2 資訊中心DB2
- INBOUND_CONNECT_TIMEOUT(zt)
- dojo.connect初解
- 17、Connect-the-dots(VulnHub)
- MQTT 協議 -- CONNECT & CONNACKMQQT協議
- Linux Use ODBC Connect OracleLinuxOracle
- Golang 如何操作DB2的?GolangDB2
- db2 hadr_spool_limitDB2MIT
- db2大表統計DB2
- DB2常用命令DB2
- DB2 Port (Network Security) RequirementsDB2UIREM
- DB2效能最佳化DB2
- DB2日誌相關DB2
- Host 'localhost' is not allowed to connect to this MySQL serverlocalhostMySqlServer