Created
March 18, 2016 03:11
-
-
Save MOOOWOOO/edc96ccbeedcb674811f to your computer and use it in GitHub Desktop.
Python连接Access数据库或读取mdb文件内容
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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