python调用mysql执行duplicate简单例子
2015-01-30 21:43
441 查看
#!/usr/bin/python import MySQLdb db=MySQLdb.connect("localhost","root","openos","python") cur=db.cursor() try: sql="""INSERT INTO A (ID,NAME) VALUES (112,'%s') ON DUPLICATE KEY UPDATE NAME=VALUES(NAME);""" % "landpack" cur.execute(sql) db.commit() except MySQLdb.Error,e: print "MySQL error %d:%s" % ( e.args[0],e.args[1])
代码片段1如上:
#!/usr/bin/python import MySQLdb db=MySQLdb.connect("localhost","root","openos","python") cur=db.cursor() try: sql="""INSERT INTO B (ID,NAME,SEX,AGE) VALUES (12,'%s','%s',%d) ON DUPLICATE KEY UPDATE NAME=VALUES(NAME), SEX=VALUES(SEX),AGE=VALUES(AGE);""" % ("mac","G",45) cur.execute(sql) db.commit() except MySQLdb.Error,e: print "MySQL error %d:%s" % ( e.args[0],e.args[1])
代码片段2如上:
相关文章推荐
- Python中实现远程调用(RPC、RMI)简单例子
- 【转】Python中实现远程调用(RPC、RMI)简单例子
- Python自动化测试例子--一个简单的自动化测试用例脚本--批量执行测试用例
- Python简单调用MySQL存储过程并获得返回值的方法
- 关于php如何调用python最简单的例子
- Python简单调用MySQL存储过程并获得返回值的方法
- Python中实现远程调用(RPC、RMI)简单例子
- ubuntu下c调用mysql的简单例子
- Python中实现远程调用(RPC、RMI)简单例子
- c与mysql连接和一个简单查询的例子
- ajax 调用webservice的简单例子
- C#调用存储过程简单完整例子
- C#调用存储过程简单完整例子
- 一个简单的客户端调用xmlHttp的ajax例子
- AJAX 调用Web Services 的简单例子
- 用Python ZSI写web service的简单例子
- ajax 调用webservice的简单例子
- JAVA实现动态类的调用简单例子
- 供LoadRunner调用的一个简单Dll例子
- 一个简单调用webservice的例子