1 #导入模块
 2 import sqlite3
 3 #创建连接
 4 con = sqlite3.connect('d:/sqlite3Demo/demo.db')
 5 #创建游标对象
 6 cur = con.cursor()
 7 #创建查询SQL
 8 sql = 'select * from t_person'
 9 try:
10     cur.execute(sql)
11     #获取结果集合,获取一条数据
12     person = cur.fetchone()
13     print(person)
14 except Exception as e:
15     print(e)
16     print("数据查询失败")
17 finally:
18     #关闭游标
19     cur.close
20     #关闭连接
21     con.close
(1, '张三', 24)

 

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2021-08-17
  • 2021-08-08
  • 2022-01-09
  • 2021-08-28
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2021-12-21
  • 2021-11-03
  • 2022-01-05
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-06-18
相关资源
相似解决方案