Python 读取 .mdb文件信息

 

#  话不多说,码上见分晓!

使用模块: pypyodbc

例子和安装详见:

https://github.com/jiangwen365/pypyodbc/

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = "loki"
import time
import pypyodbc as mdb

# 连接mdb文件
connStr = (r'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\MDB_demo\demo.mdb;'
           r'Database=bill;'
           )
conn = mdb.win_connect_mdb(connStr)

# connStr = (
#     r'Driver={SQL Sever};'
#     r'Server=sqlserver;'
#     r'Database=bill;'
#     r'UID=sa;'
#     r'PWD=passwd'
# )
#
# conn = mdb.connect(connStr)
# 创建游标
cur = conn.cursor()

cur.execute('SELECT * FROM bill;')

for col in cur.description:
    # 展示行描述
    print(col[0], col[1])
result = cur.fetchall()

for row in result:
    # 展示个字段的值
    print(row)
    print(row[1], row[2]

 

 

参考资料:

https://www.jianshu.com/p/00b53a386c2a

https://blog.csdn.net/jisuanjiguoba/article/details/73163721

https://www.jb51.net/article/110022.htm

https://blog.csdn.net/LIYUANNIAN/article/details/82937350

posted @ 2019-06-17 15:22  Cong0ks  阅读(6782)  评论(0编辑  收藏  举报