Python Programming - Standard Libraries - Discussion

Discussion Forum : Standard Libraries - General Questions (Q.No. 75)
75.
How can you use the sqlite3 module in Python to connect to an SQLite database and execute a query?
sqlite3.connect(database)
sqlite3.query(database, sql)
sqlite3.execute(database, sql)
sqlite3.query(sql)
Answer: Option
Explanation:
import sqlite3

# Example usage of sqlite3 module for connecting to an SQLite database and executing a query
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)')
connection.commit()
connection.close()
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.