# -*- coding: utf-8 -*-
'''
不同的SQL server版本對應的DRIVER字段不同。對應關系如下
{SQL Server} - released with SQL Server 2000
{SQL Native Client} - released with SQL Server 2005 (also known as version 9.0)
{SQL Server Native Client 10.0} - released with SQL Server 2008
{SQL Server Native Client 11.0} - released with SQL Server 2012
'''
import json,pyodbc
conn=pyodbc.connect(r'DRIVER={SQL Server Native Client 10.0};SERVER=1.1.1.1;DATABASE=test_1;UID=1;PWD=123')
cursor = conn.cursor()
cursor.execute("select * from A2017")
#以下3種方式
#使用 fetchone() 方法依次獲取結果中需要的內容:
rows = cursor.fetchone()
for row in rows:
print (row)
#使用fetchall()直接獲取結果集list
rows = cursor.fetchall()
for row in rows:
print(row)
#一次獲取所有內容
for row in cursor:
print(row)