数据库
首页 > 数据库> > pymysql操作数据更新

pymysql操作数据更新

作者:互联网

import  pymysql
list=['anhui', 'beijing', 'chongqing', 'fujian', 'gansu', 'guangdong', 'guangxi', 'guizhou', 'hainan', 'hebei', 'heilongjiang', 'henan', 'hubei', 'hunan', 'jiangsu', 'jiangxi', 'jilin', 'liaoning', 'neimenggu', 'ningxia', 'qinghai', 'shaanxi', 'shandong', 'shanghai', 'shanxi', 'sichuan', 'tianjing', 'xinjiang', 'xizang', 'yunnan', 'zhejiang']
for i in list:
    print(i)
    conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='zsz')
    cursor = conn.cursor()
    sql3= 'update '+i+' set rate=AJS/A where Time between 2010.0 and 2021.0;'
    try:
        cursor.execute(sql3)
        print(‘执行成功’)
        conn.commit()
    except Exception as e:
        conn.rollback()
    finally:
        conn.close()

 

标签:sql3,list,更新,cursor,pymysql,print,操作,conn
来源: https://www.cnblogs.com/yaya-dsx/p/16325086.html