ITPub博客

首页 > 数据库 > > pymysql没插入成功也没报错cursor.execute

pymysql没插入成功也没报错cursor.execute

作者:apnic 时间:2019-09-17 09:50:25 0 删除 编辑
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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Django+webpack
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    121
  • 访问量
    792