zoukankan      html  css  js  c++  java
  • python + mysql 实现表更新数据

    实例如下:

    import pymysql

    def Update_Set():
    #打开数据库链接
    db = pymysql.connect("localhost","root","123456","test")

    # 使用cursor()方法获取操作游标
    cursor = db.cursor()

    #SQL语句更新数据
    sql = """UPDATE student SET address = '东莞' WHERE ID = %s"""%(2)

    try:
    # 执行SQL语句
    cursor.execute(sql)
    # 提交到数据库执行
    db.commit()
    print("更新数据成功")

    except Exception as e:
    print("数据更新出错:case%s"%e)
    #发生错误是回滚
    db.rollback()

    finally:
    # 关闭游标连接
    cursor.close()
    # 关闭数据库连接
    db.close()

    def main():
    Update_Set()

    if __name__ == '__main__':
    main()






  • 相关阅读:
    CSS display使用
    WPF触发器
    WPF动画2
    WPF动画2
    WPF 动画1
    CSS 媒体查询
    [Leetcode] Rotate List
    [Leetcode] Add Two Numbers
    [Leetcode] Sort List
    [Leetcode] Reverse Linked List II
  • 原文地址:https://www.cnblogs.com/Teachertao/p/11285474.html
Copyright © 2011-2022 走看看