Pyhton Sqlite3手机数据库

代码+结果

Code

python 复制代码
import sqlite3
conn=sqlite3.connect('test.db')
cs=conn.cursor()
create_tb_sql='''
        create table if not exists info(
        id int primary  key,
        name text,
        age int
        )
'''
cs.execute(create_tb_sql)

# cs.execute('insert into info(id,name,age) values(3,"dog_Senior",22)')
conn.commit()
# cs.execute('select name from info')
cs.execute('select * from info')
result= cs.fetchall()
print(result)

期间错误:

Python连接sqlite数据库,查询报错 sqlite3.OperationalError: no such table: userInfo

原因+解决措施:

1、数据库并没有建立该表。 【重新再建一个数据库】

2、程序没有找到该数据库中有该表。

select name from sqlite_master where type='table' order by name;

查询的结果如果是 [ ] 空,但是你可以点击数据表能看到数据,这就是数据库里面的表没有被检索到。

相关案例:

https://blog.csdn.net/m0_52103877/article/details/131093379

相关推荐
余衫马40 分钟前
CentOS7 离线安装 Postgresql 指南
数据库·postgresql
E___V___E1 小时前
MySQL数据库入门到大蛇尚硅谷宋红康老师笔记 高级篇 part 2
数据库·笔记·mysql
m0_748254882 小时前
mysql之如何获知版本
数据库·mysql
mikey棒棒棒2 小时前
Redis——优惠券秒杀问题(分布式id、一人多单超卖、乐悲锁、CAS、分布式锁、Redisson)
数据库·redis·lua·redisson·watchdog·cas·并发锁
水手胡巴3 小时前
oracle apex post接口
数据库·oracle
史迪仔01126 小时前
【SQL】SQL多表查询
数据库·sql
Quz6 小时前
MySQL:修改数据库默认存储目录与数据迁移
数据库·mysql
Familyism6 小时前
Redis
数据库·redis·缓存
隔壁老登6 小时前
查询hive指定数据库下所有表的建表语句并生成数据字典
数据库·hive·hadoop
sekaii7 小时前
ReDistribution plan细节
linux·服务器·数据库