1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| import sqlite3
conn = sqlite3.connect("test.db") # 打开或创建数据库文件
print("成功打开数据")
c = conn.cursor() # 获取游标
sql1 = '''
insert into company(id, name,age,address, salary)
values(1,'张三',32,"成都",8000);
'''
sql2 = '''
insert into company(id, name,age,address, salary)
values(2,'李四',30,"重庆",15000);
'''
c.execute(sql1) # 执行sql语句
c.execute(sql2) # 执行sql语句
conn.commit() # 提交数据库操作
conn.close() # 关闭数据库连接
print("插入数据完毕")
|