Python编程语言简单易用,很方便开发人员快速学习使用。而且其应用范围也比较广泛。我们今天就先来一起看看有关Python连接SqlServer的一些基本应用方式,以此来满足我们对这方面的学习需要。
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
以上就是对Python连接SqlServer的相关介绍。
【编辑推荐】