`
Thomas会Coding
  • 浏览: 93185 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Python操作sqlite数据库的一些记录

 
阅读更多

Python 内置了sqlite的模块

import sqlite3

connection=sqlite3.connect('coachdata.sqlite')
cursor=connection.cursor();
'''cursor.execute("""create table athletes(id integer primary key autoincrement unique not null,
                name text not null,
                dob date not null
                )""")'''
#创建表
#cursor.execute("insert into athletes(name,dob) values(?,?)",('zzc','1990-0210'));
#插入表
cursor.execute("select * from athletes")
#查询表
print cursor.fetchall()
connection.commit()
#一定要提交
connection.close()

 cursor.fetchone()返回下一个数据行

cursor.fetchmany()返回多个数据行

cursor.fetchall()返回所有数据

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics