python 連線sqlite及操作

2022-07-07 11:06:09 字數 922 閱讀 5297

import sqlite3

#查詢def load(table):

#連線資料庫

con = sqlite3.connect("e:/datebase/sqlitestudio/park.db")

#獲得游標

cur = con.cursor()

#查詢整個表

cur.execute('select *from '+table)

lists = ['name','password']

if table == 'login':

#將資料庫列名存入字典

colnames =

將字典和資料庫的資料一起存入列表,獲得了記錄字典

rowdicts = [dict(zip(lists, row)) for row in cur.fetchall()]

else:

rowdicts =

for row in cur:

con.commit()

cur.close()

return rowdicts

#插入資料

def insert_data(id,name,money):

con = sqlite3.connect("e:/datebase/sqlitestudio/park.db")

cur = con.cursor()

#使用sql語句插入

cur.execute('insert into charge values (?,?,?)', (id,name, money))

#插入後進行整表查詢,看是否成功插入

cur.execute('select *from charge')

print(cur.fetchall())

con.commit()

cur.close()

Python連線SQLite資料庫

sqlite作為一款輕型資料庫,管理工具有很多,比如sqlite expert professional,很適合用來儲存python 爬蟲的相關資料,下面列出基本的增刪查改操作 讀取操作 conn1 sqlite3.connect board.databasepath conn1.row facto...

Python連線SQLite資料庫

python 3.7.4 sqlite3def init self,path 建構函式 資料庫路徑path,若存在資料庫則連線,否則建立.db檔案 連線到指定資料庫 self.connect sqlite3.connect path self.cursor self.connect.cursor 初...

ASP odbc 連線 SQLITE 及一些測試。

先安裝odbc驅動。然後安裝個sharpplus sqlite developer 用它就可以建立個sqlite資料庫 插入資料測試 dim conn dim connstr dbpath db 資料庫路徑名 set conn createobject adodb.connection 定義物件 c...