Python連接SqlServer基本應(yīng)用方式淺析
作者:佚名
Python連接SqlServer這一操作技術(shù)在實(shí)際程序開發(fā)中是一個(gè)比較常用到的操作技術(shù)。我們?cè)谶@里先為大家介紹一下這一操作的基本方式,以方便理解。
Python編程語言簡(jiǎn)單易用,很方便開發(fā)人員快速學(xué)習(xí)使用。而且其應(yīng)用范圍也比較廣泛。我們今天就先來一起看看有關(guān)Python連接SqlServer的一些基本應(yīng)用方式,以此來滿足我們對(duì)這方面的學(xué)習(xí)需要。
Python連接SqlServer代碼示例:
- import pymssql
- #connect database
- conn=pymssql.connect(host="192.168.1.28",user="boomink",
password="boomink",database="boomink")- cur=conn.cursor()
- print '========================================'
- cur.execute("exec Orders_GetTest1 @Value=%s ",('2005-01-01',))
- while 1:
- print cur.fetchall()
- if 0 == cur.nextset():
- break
- data=cur.fetchall()
- print data
- print '========================================'
- #cur.execute("exec Orders_GetTest")
- cur.execute("exec Orders_GetTest2 @Value1=%s,@Value2=%s",('Ruan','Yu'))
- while 1:
- print cur.fetchall()
- if 0 == cur.nextset():
- break
- data=cur.fetchall()
- print data
- print '========================================'
- cur.execute("exec Orders_GetTracking @BeginDate=%s,
@EndDate=%s",('2005-01-01','2008-01-01'))- record = cur.fetchall()
- while 1:
- print cur.nextset()
- for r in record:
- print '========================================'
- a=r[1]
- print 'OrderId:%s' % r[0]
- print r
- print '========================================'
- if 0 == cur.nextset():
- break
- print "rnrow count:%d" % cur.rowcount
- #commit the connection
- conn.commit
- #close the connection
- conn.close
以上就是對(duì)Python連接SqlServer的相關(guān)介紹。
【編輯推薦】
責(zé)任編輯:曹凱
來源:
博客園