-- coding: utf-8 --
import sqlite3
conn = sqlite3.connect(‘testdemo.db’)
创建一个Cursor:
cursor = conn.cursor()
执行一条SQL语句,创建user表:
cursor.execute(‘create table user (id varchar(20) primary key, name varchar(20))’)
继续执行一条SQL语句,插入一条记录:
cursor.execute(‘insert into user (id, name) values (‘1’, ‘Michael’)’)
cursor.execute(‘select * from user where id=?’, (‘1’,))
value=cursor.fetchall()
print (value)
cursor.rowcount
关闭Cursor:
cursor.close()
提交事务:
conn.commit()
关闭Connection:
conn.close()
本文来自 言寡 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/qq_21406125/article/details/79642193?utm_source=copy
本文演示了使用Python的sqlite3模块进行数据库操作的过程,包括连接数据库、创建表、插入数据及查询数据等基本操作。
4716

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



