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()返回所有数据
本文介绍如何使用Python内置的sqlite3模块进行数据库操作,包括创建表、插入数据、查询数据等基本功能,并展示了如何通过execute方法执行SQL语句。
120

被折叠的 条评论
为什么被折叠?



