Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Created March 18, 2016 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MOOOWOOO/edc96ccbeedcb674811f to your computer and use it in GitHub Desktop.
Save MOOOWOOO/edc96ccbeedcb674811f to your computer and use it in GitHub Desktop.
Python连接Access数据库或读取mdb文件内容
# -*- coding:utf-8 -*-
"""
"""
import pypyodbc
__author__ = "Jux.Liu"
# pypyodbc.lowercase = False
db_file = r'D:\att2000.mdb'
user = 'Administrator'
password = ''
connection_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;UID=%s;PWD=%s' % (db_file, user, password)
conn = pypyodbc.win_connect_mdb(connection_string)
SQL = '''SELECT * FROM CHECKINOUT;'''
cur = conn.cursor()
cur.execute(SQL)
while True:
row = cur.fetchone()
if row is None:
break
else:
print(u'Userid: {0}, checktime: {1}, checktype: {2}, verifycode: {3}, sensorid: {4}'.format(row[0], row[1],row[2],row[3],row[4]))
cur.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment