Python module operation using the Access database pypyodbc

Recently used office to the Access database, Python be the database using SQL statements CRUD module operation by pypyodbc

Installation pypyodbc module

pip install pypyodbc

First, connect to the database

import pypyodbc
path = u'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=' + r"这里是数据库文件路径"
db = pypyodbc.win_connect_mdb(path)
cur = db.cursor()

Then you can use SQL statements to operate the Access database

cur.execute("这里是SQL语句")
cur.fetchall()      # 返回查询的结果,可以使用变量接收返回值

If you need to modify the contents of the database, do not forget to submit the revised

cur.execute("这里是SQL语句")
cur.commit()      # 提交操作

 

Published 21 original articles · won praise 9 · views 9541

Guess you like

Origin blog.csdn.net/Zhang_Chao_1998/article/details/101196852