sqliteHow do I insert data into a SQLite database using Python?
Inserting data into a SQLite Database using Python is a simple process. The following example code will insert a record into the 'users' table of a SQLite database:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("INSERT INTO users VALUES ('John', 'Doe', '[email protected]')")
conn.commit()
conn.close()
The code above does the following:
- Imports the sqlite3 module.
- Connects to the 'example.db' database.
- Creates a cursor object.
- Executes an SQL statement to insert a record into the 'users' table.
- Commits the changes to the database.
- Closes the connection to the database.
Helpful links
More of Sqlite
- How do I extract the year from a datetime value in SQLite?
- How do I format a date in SQLite using the YYYYMMDD format?
- How do I use SQLite xfilter to filter data?
- How do I decide between using SQLite and MySQL for my software development project?
- How do I use a SQLite viewer to view my database?
- How do I use the SQLite sequence feature?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I use SQLite Studio to manage my database?
- How do I call sqlitepcl.raw.setprovider() when using SQLite?
- How to configure SQLite with XAMPP on Windows?
See more codes...