Python SQLite - Establishing Connection


Advertisements

To establish connection with SQLite Open command prompt, browse through the location of where you have installed SQLite and just execute the command sqlite3 as shown below −

Command Prompt SQLite

Establishing Connection Using Python

You can communicate with SQLite2 database using the SQLite3 python module. To do so, first of all you need to establish a connection (create a connection object).

To establish a connection with SQLite3 database using python you need to −

  • Import the sqlite3 module using the import statement.

  • The connect() method accepts the name of the database you need to connect with as a parameter and, returns a Connection object.

Example

import sqlite3
conn = sqlite3.connect('example.db')

Output

print("Connection established ..........")
Advertisements