Update operation of python's mysql database

a code

import pymysql
# Open database connection
db = pymysql.connect("localhost","root","root","db_test01" )
# Use the cursor() method to get the operation cursor
cursor = db.cursor()
# SQL update statement
sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 WHERE SEX = '%c'" % ('M')
try:
   # Execute the SQL statement
   cursor.execute(sql)
   # Submit to the database for execution
   db.commit()
   print("update OK")
except:
   # rollback on error
   db.rollback()
# close the database connection
db.close()

 

Second run results
update OK

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327059150&siteId=291194637