python + mysql implemented to update the data table

Examples are as follows:

pymysql Import 

DEF Update_Set ():
# Open the database link
db = pymysql.connect ( "localhost", "root", "123456", "the Test")

# using the cursor () method to get the cursor operating
the Cursor = db.cursor ()

# SQL statement update data
sql = "" "uPDATE student SET address = ' Dongguan' the WHERE ID =% S" ""% (2)

the try:
# execute SQL statements
the cursor.execute (SQL)
# submitted to the database to perform
the db.commit ( )
Print ( "data update success")

the except Exception AS E:
Print ( "update data error:% S Case" E%)
# error occurs rollback
db.rollback ()

the finally:
# close connection cursor
cursor.Close ()
# close the connection
db.Close ()

DEF main ():
Update_Set()

if __name__ == '__main__':
main()


 





Guess you like

Origin www.cnblogs.com/Teachertao/p/11285474.html