Python Data Access 简明教程

Python SQLite - Establishing Connection

要建立与 SQLite 的连接,打开命令提示符,浏览到你安装了 SQLite 的位置,然后执行 @[s2] 命令,如下所示:

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 −

establish connection

Establishing connection using python

你可以使用 SQLite3 python 模块与 SQLite2 数据库进行通信。要做到这一点,首先你需要建立一个连接(创建一个连接对象)。

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).

要使用 python 建立与 SQLite3 数据库的连接,你需要:

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

  1. Import the sqlite3 module using the import statement.

  2. 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 ..........")