python通过参数方式向mysql中添加数据,pythonmysql,#!/usr/bin/p
文章由Byrx.net分享于2019-03-23 10:03:56
python通过参数方式向mysql中添加数据,pythonmysql,#!/usr/bin/p
#!/usr/bin/pythonimport MySQLdb# Open database connectiondb = MySQLdb.connect("localhost","testuser","test123","TESTDB" )# prepare a cursor object using cursor() methodcursor = db.cursor()# Prepare SQL query to INSERT a record into the database.sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \ LAST_NAME, AGE, SEX, INCOME) \ VALUES ('%s', '%s', '%d', '%c', '%d' )" % \ ('Mac', 'Mohan', 20, 'M', 2000)try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit()except: # Rollback in case there is any error db.rollback()# disconnect from serverdb.close()
相关内容
- python数组插入新元素,python数组新元素,li=['a', 'b'
- 用Python实现一个简单的算术游戏,python实现算术,#!/us
- 在windows下安装python的easy_install工具,pythoneasy_install,在
- python通过cStringIO实现临时内存文件访问,pythoncstringio
- python通过wxPython打开并播放wav文件,pythonwxpython,''' wx_
- python计算牛顿迭代多项式,python牛顿多项式,''' p = eva
- N lowest eigenvalues of the tridiagonal matrix in python,,''' r = l
- python实现二分查找代码演示,python二分,def BinarySe
- python多线程模块thread使用范例,pythonthread,#!/usr/bin/p
- Python中最快的字典排序方法,python字典排序,def sbv0(ad
评论关闭