콘텐츠로 이동

SQLite로 Select 하기

SQLite DB로 부터 저장된 데이터 조회하기

import sqlite3

# SQLite 데이터베이스에 연결 (파일이 없다면 자동으로 생성됨)
conn = sqlite3.connect('customer.db')  # 'customer.db'는 데이터베이스 파일 이름
cursor = conn.cursor()  # 커서 객체 생성

# 데이터 조회
cursor.execute('SELECT * FROM as_list')

# 결과 출력
rows = cursor.fetchall()
for row in rows:
    print(row)

# 데이터베이스 연결 종료
conn.close()