oracle 连接法

https://blog.csdn.net/crazyultimate/article/details/52759238

https://blog.csdn.net/whatday/article/details/84950360

 https://www.cnblogs.com/daisy89/p/5307727.html

import pymysql.cursors
# 连接数据库
connect = pymysql.Connect(
host='localhost',
port=3310,
user='user',
passwd='123',
db='test',
charset='utf8'
)
# 事务处理
sql_1 = "UPDATE staff SET saving = saving + 1000 WHERE user_id = '1001' "
sql_2 = "UPDATE staff SET expend = expend + 1000 WHERE user_id = '1001' "
sql_3 = "UPDATE staff SET income = income + 2000 WHERE user_id = '1001' "

try:
cursor.execute(sql_1) # 储蓄增加1000
cursor.execute(sql_2) # 支出增加1000
cursor.execute(sql_3) # 收入增加2000
except Exception as e:
connect.rollback() # 事务回滚
print('事务处理失败', e)
else:
connect.commit() # 事务提交
print('事务处理成功', cursor.rowcount)

# 关闭连接
cursor.close()
connect.close()
————————————————
版权声明:本文为CSDN博主「幽梦萧瑟」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mengyangcust/article/details/84752342

原文地址:https://www.cnblogs.com/xupanfeng/p/12921401.html