Python SQLite - 建立連線



要與 SQLite 建立連線,請開啟命令提示符,瀏覽到已安裝 SQLite 的位置,然後執行命令sqlite3,如下所示:

Establish Connection

使用 Python 建立連線

您可以使用 SQLite3 Python 模組與 SQLite2 資料庫進行通訊。為此,首先需要建立連線(建立連線物件)。

要使用 Python 與 SQLite3 資料庫建立連線,您需要:

  • 使用 import 語句匯入 sqlite3 模組。

  • connect() 方法接受您需要連線的資料庫名稱作為引數,並返回一個 Connection 物件。

示例

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

輸出

print("Connection established ..........")
廣告