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 to configure SQLite with XAMPP on Windows?
- How can I use SQLite with Zabbix?
- How do I use SQLite with Visual Studio?
- How do I show the databases in SQLite?
- How do I use regular expressions to query a SQLite database?
- How can SQLite and ZFS be used together for software development?
- How can I use SQLite with WebAssembly?
- How do I use SQLite UNION to combine multiple SELECT queries?
- How do I set up an ODBC driver to connect to an SQLite database?
- How do I install SQLite on Windows?
See more codes...