【发布时间】:2016-01-20 09:54:52
【问题描述】:
我想将 ms access db 与烧瓶框架一起使用。我的问题是如何配置它以及如何以json格式将数据存储在ms access db中。
【问题讨论】:
我想将 ms access db 与烧瓶框架一起使用。我的问题是如何配置它以及如何以json格式将数据存储在ms access db中。
【问题讨论】:
这可以通过使用pyodbc 库来实现:
创建连接:
cnxn = pyodbc.connect('"Driver={Microsoft Access Driver (*.mdb)};DBQ=<path to MDB>;"')
cursor = cnxn.cursor()
选择示例:
cursor.execute("select user_id, user_name from users")
row = cursor.fetchone()
if row:
print(row)
删除示例:
cursor.execute("delete from products where id <> ?", 'pyodbc')
print('Deleted {} inferior products'.format(cursor.rowcount))
cnxn.commit()
带有安装说明的官方文档可以在这里找到:http://mkleehammer.github.io/pyodbc/
【讨论】: