安装教程
python2.5以后安装包自带sqlite3的软件包,直接导入即可
sqlite3比较小,不需要单独启动程序
sqlite3已经内嵌子python中
python中使用
1.首先导入sqlite3
import sqlite3
conn = sqlite3.connect("example.db")
c = conn.cursor()
c.execute("CREATE TABLE stocks(date text, trans text, symbol text, qty real, price real)")
c.execute()
conn.commit()
conn.close()
for row in c.execute("SELECT * FROM stocks ORDER BY price"):
print(row)
connection对象
connect(database)
sqlite3.Connection.execute()
sqlite3.Connection.cursor()
sqlite3.Connection.commit()
sqlite3.Connection.rollback()
sqlite3.Connection.close()
Cursor对象 游标对象
close() # 关闭游标
execute() # 执行sql语句
executemany() # 重复执行多次sql语句
executescript() # 一次执行多条sql语句
fetchall() # 从结果集中返回所有行记录
fetchmany() # 从结果集中返回多行记录
fetchone() # 从结果集中返回一行记录
Python 编写数据库