import sqlite3
conn = sqlite3.connect("mrsoft.db")
cursor = conn.cursor()
cursor.execute('insert into user(id,name) values("1","AR")')
cursor.execute('insert into user(id,name) values("2","QR")')
cursor.execute('insert into user(id,name) values("3","SR")')
cursor.execute('insert into user(id,name) values("4","GR")')
cursor.execute("select* from user")
result1 = cursor.fetchall()
print(result1)
cursor.close()
conn.close()
运行结果:
当注释掉插入语句
import sqlite3
conn = sqlite3.connect("mrsoft.db")
cursor = conn.cursor()
# cursor.execute('insert into user(id,name) values("1","AR")')
# cursor.execute('insert into user(id,name) values("2","QR")')
# cursor.execute('insert into user(id,name) values("3","SR")')
# cursor.execute('insert into user(id,name) values("4","GR")')
cursor.execute("select* from user")
result1 = cursor.fetchall()
print(result1)
cursor.close()
conn.close()
运行结果:
已经在文件中创建数据库user,包含id和name两个属性,类型为int(10)和varchar(20)。
想知道这是什么原因,感觉是插入的数据没有保存到数据库中,求解。