Python 学习笔记五----使用sqlite数据库
2014-11-05 09:59
232 查看
import sqlite3 def Test1(): con = sqlite3.connect("D:\\test.db") con = sqlite3.connect("memory") cur =con.cursor() try: cur.execute('create table score(id integer primary key,name varchar(10),scores integer)') cur.execute("insert into score values(0,'Rose',87)") cur.execute("insert into score values(1,'Alice',78)") cur.execute("insert into score values(2,'Helon',100)") cur.execute("insert into score values(3,'Tom',98)") cur.execute("insert into score values(4,'jack',198)") #cur.execute("insert into score values(4,'jack',198)") #Don't execute the following statement when except occurs cur.execute("insert into score values(5,'Tony',198)") cur.execute("insert into score values(6,'David',99)") cur.execute("update score set scores =? where id=?",(45,3)) #With Param cur.execute("update score set name=? where id=?",("John",0)) #With Param cur.execute("delete from score where id =1") except Exception,e: print "There are some except",e con.commit() print "Insert Complete" print "-----------------------------------------" print "Last row id is ",cur.lastrowid cur.execute('select * from score') print cur.fetchall() print "----------------------------------------" cur.execute("select count(*) from score") print "Current Rows is :",cur.fetchall()[0] cur.close() con.close() if __name__ =='__main__': Test1() print "hello world"
相关文章推荐
- python学习笔记:datetime使用小结
- python学习笔记+使用技巧
- Python 学习笔记(三) 使用字符串
- 【Cocos2D-X 学习笔记】Cocos2D-x 3.0+VS开发环境搭建[使用Python]
- Python ORM框架SQLAlchemy学习笔记之映射类使用实例和Session会话介绍
- Python 学习笔记【使用元组的注意点】
- Python学习笔记之疑问 9:如何使用For语句
- Python3.x学习笔记[2.5]灵活使用urllib与re
- python学习笔记之二:使用字符串
- python 学习笔记 11 -- 使用参数使你的程序变得更性感
- [iOS学习笔记] 通过FMDataBase使用sqlite数据库
- Python学习笔记--help命令使用
- SVM学习笔记(2)LIBSVM在python下的使用
- Python学习笔记-字典使用
- mongoDB学习笔记3--python下使用
- linux 学习笔记 (3) —— 使用python
- Python学习笔记—PyQuery库的使用总结
- Python学习笔记--为什么需要使用__name__=='__main__'
- python学习笔记:字典的使用示例详解
- python学习笔记--循环使用