【1-4】pythondb的rollback()用法
来源:互联网 发布:快讯通软件 编辑:程序博客网 时间:2024/05/14 13:08
1.效果图
<module 'MySQLdb' from 'C:\Python27\lib\site-packages\MySQLdb\__init__.pyc'>
<_mysql.connection open to 'localhost' at 26e65b8>
<MySQLdb.cursors.Cursor object at 0x000000000296CC50>
userid=1, username=a
userid=2, username=b
userid=3, username=c
userid=4, username=d
userid=5, username=e
userid=6, username=f
userid=7, username=h
userid=9, username=i
1
1
(1054, "Unknown column 'userd' in 'where clause'")
2.源代码
# -*- coding:utf-8 -*-
import MySQLdb
print MySQLdb
conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='t1',port=3306)
cursor=conn.cursor()
print conn
print cursor
sql = "select * from user"
cursor.execute(sql)
rs = cursor.fetchall()
for row in rs:
print "userid=%s, username=%s" % row
sql_insert = "insert into user(userid,username) values(10,'name10')"
sql_update = "update user set username='name9' where userid=9"
sql_delete = "delete from user where userd<4"
try:
cursor.execute(sql_insert)
print cursor.rowcount
cursor.execute(sql_update)
print cursor.rowcount
cursor.execute(sql_delete)
print cursor.rowcount
conn.commit()
except Exception as e:
print e
conn.rollback()
rs = cursor.fetchall()
for row in rs:
print "userid=%s, username=%s" % row
cursor.close()
conn.close()
- 【1-4】pythondb的rollback()用法
- pythonDB
- COMMIT和ROLLBACK的用法
- COMMIT和ROLLBACK的用法
- 【1-3】pythondb增删改查
- PL/SQL中savepoint和rollback的用法
- SQL 事务 begin tran、commit tran、rollback tran 的用法
- pythondb操作
- SQL事务用法begin tran,commit tran和rollback tran的用法
- Hibernate的rollback方法
- 队列Rollback的设计
- ROLLBACK的工作过程
- 【rollback】
- 从SQL语言的分类谈COMMIT和ROLLBACK的用法
- 从SQL语言的分类谈COMMIT和ROLLBACK的用法
- 从SQL语言的分类谈COMMIT和ROLLBACK的用法
- 从SQL语言的分类谈COMMIT和ROLLBACK的用法
- 从SQL语言的分类谈COMMIT和ROLLBACK的用法
- 通过GSON解析json
- C#面向对象
- 三分 3
- 在代码中使用assets目录中的图片
- strtoupper.php
- 【1-4】pythondb的rollback()用法
- IOS中通知中心(NSNotificationCenter)的使用
- android图形处理之 Matrix方法
- 猜数字啦
- C# dateTime类型之subTract用法
- Add Two Numbers
- Git 常用命令
- Fragment
- 连连看