1 def save_db(cons):
2 db = pymysql.connect(host = '127.0.0.1' , user = 'root' , password = 'root' , port = 3306)
3 cursor = db.cursor()
4 sql = 'INSERT INTO quote(jy_time,open_price,high_price,low_price,over_price,zhangdiee,zhangdief,chengjiaol,chengjiaoj,zhenfu,huanshoul) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
5 print('插入中...')
6 try:
7 cursor.execute(sql,(cons))
8 print(cons)
9 db.commit()
10 except:
11 print('失败了啊')
12 db.rollback()
13 db.close()代码如上,`cursor.execute(sql,(cons))`是执行失败了么,执行结果:
D:\ProgramData\************\python.exe E:/*******/project/test/test.py
插入中...
失败了啊
插入中...
失败了啊
插入中...明显是try失败了,然后就print('失败了啊')
可是也没报错呀,为啥没插入成功呢
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1282/viewspace-3124611/ ,如需转载,请注明出处,否则将追究法律责任。