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

相关推荐
禹凕36 分钟前
MySQL——基础知识(正则表达式)
数据库·mysql·正则表达式
SmartBrain2 小时前
FastAPI实战(第三部分):浏览历史的接口开发详解
数据库·人工智能·aigc·fastapi
山岚的运维笔记2 小时前
SQL Server笔记 -- 第77章:文件组
数据库·笔记·sql·microsoft·oracle·sqlserver
有点心急10213 小时前
Python 入门
服务器·数据库·python
独泪了无痕3 小时前
Mac Homebrew 安装 MySQL 指南
数据库·mysql·mac
l1t3 小时前
DeepSeek总结的PostgreSQL 19新功能:第二部分
数据库·postgresql
fchampion3 小时前
MYSQL自学笔记
数据库·笔记·mysql
XiaoHu02073 小时前
MySQL基础(第一弹)
数据库·c++·mysql
惜分飞4 小时前
rose双机引起文件系统损坏使得数据库异常故障处理---惜分飞
数据库·oracle
fchampion4 小时前
MYSQL分析案例
数据库·mysql