The sqlite3 module in python queries one or more pieces of data

#import module
import sqlite3
#create link
con = sqlite3.connect('C:\python_learn\DBA\SQLite3demo\sqlite3demo.db')
#create cursor object
cur = con.cursor()
#write sql statement
sql = "select * from  t_person "
# execute statement
try:
    cur.execute(sql)
    # get result set
    person_all = cur.fetchall() #Get all data
    # person_all = cur.fetchone() #Get a piece of data
    for person in person_all:
        print(person)
    print("Query data succeeded")
except Exception as e:
    print(e)
    print("Failed to query data")
finally:
    cur.close()
    con.close()

Tags: The sqlite3 module in python queries one or more pieces of data

python learning

Related: The sqlite3 module in python queries one or more pieces of data