标签:use als imp 多次 lse password try sql har
import pymssql
conn = pymssql.connect(host=‘szs‘,server=‘SZS\SQLEXPRESS‘,port=‘51091‘, user=‘python‘, password=‘python‘, database=‘python‘,charset=‘utf8‘,autocommit=True)
cur = conn.cursor()
sql = "insert into [novals] values (‘python‘,‘python‘,‘python‘,‘python‘);COMMIT "
try:
cur.execute(sql)
except:
conn.rollback()
cur.close()
conn.close()
数据的插入需要在sql语句后加上COMMIT,同时需要在连接处设置autocommit=True,如果没有我试过插入不成功。
之前查过看见很多人说在cur.execute(sql)后面使用conn.commit(),但是我试了很多次都不成功,直到看到https://blog.csdn.net/markchiu/article/details/50833504,抱着试一试的态度,竟然成功,很无语!特此记录
python3.7 使用pymssql往sqlserver插入数据
标签:use als imp 多次 lse password try sql har
原文地址:https://www.cnblogs.com/xifengmo/p/10994712.html