pymssql 中文写入读取

#!/usr/bin/env python

# -*- coding: gb2312 -*-

import pymssql

conn = pymssql.connect(host='192.168.5.100', user='sa', password='mssql', database='TEST',charset='cp936',as_dict=True)

cur = conn.cursor()

sql_b="INSERT INTO Table1 (id,name)VALUES('13','张文君')"

cur.execute(sql_b)

conn.commit()

sql_a='SELECT * FROM Table1'

# cur.execute(sql_a.encode('cp936'))

cur.execute(sql_a)

for name in cur.fetchall():

# print row

print name[0].encode('gbk')+name[1].encode('gbk')

conn.close()

你可能感兴趣的:(sql,user,table,database,insert)