SQLite3查询一条数据_5

 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)

猜你喜欢

转载自www.cnblogs.com/monsterhy123/p/12576142.html