打印表中的行记录
也可以用这种方式
#!/bin/python
#coding=gb18030
import DB2
dsn="driver={IBM DB2 ODBC DRIVER };database=%s;hostname=%s;port=%s;protocol=tcpip;"%("dbsync","192.168.19.55","50000")
conn = DB2.connect(dsn,"administrator","db2")
cursor = conn.cursor()
cursor.execute("select * from src")
row = cursor.fetchone()
while row:
(zhujian,ziduan1,ziduan2)= (row[0],row[1],row[2])
row = cursor.fetchone()
print zhujian,ziduan1,ziduan2
cursor.close()
也可以用这种方式
import pyodbc
dsn="driver={IBM DB2 ODBC DRIVER};database=%s;hostname=%s;port=%s;protocol=tcpip;"%("dbsync","192.168.19.55","50000")
connStr = pyodbc.connect(dsn+"uid=administrator;pwd=db2;");
cursor = conn.cursor()
cursor.execute("select * from src")
row = cursor.fetchone()
while row:
(zhujian,ziduan1,ziduan2)= (row[0],row[1],row[2])
row = cursor.fetchone()
print zhujian,ziduan1,ziduan2
cursor.close()