Read data from SQLite database using Python

Here’s an example code to read data from an SQLite database using Python and the sqlite3 module

import sqlite3

# connect to the database
conn = sqlite3.connect('example.db')

# create a cursor object
cur = conn.cursor()

# execute a SELECT statement
cur.execute('SELECT * FROM customers')

# fetch all rows from the result set
rows = cur.fetchall()

# iterate over the rows and print each row
for row in rows:
    print(row)

# close the cursor and connection
cur.close()
conn.close()

In this example, we connect to an SQLite database called example.db, create a cursor object, and execute a SELECT statement to retrieve all rows from a table called customers. We then fetch all rows from the result set using the fetchall() method, iterate over the rows, and print each row to the console. Finally, we close the cursor and connection to the database using the close() method.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech