Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
query microsoft access 2010 database using python
# http://www.blog.pythonlibrary.org/2011/02/01/pywin32-adodbapi-and-ms-access/
# http://mail.python.org/pipermail/python-win32/2011-January/011086.html
from __future__ import unicode_literals
import adodbapi
import datetime
database = "Tudeng.mdb"
# access 2010
constr = 'Provider=Microsoft.ACE.OLEDB.12.0; Data Source=%s' % database
# connect to the database
conn = adodbapi.connect(constr)
# create a cursor
cur = conn.cursor()
# extract all the data
sql = '''select * from Aine'''
cur.execute(sql)
def row_tuple(item):
return tuple(map(lambda part: unicode(part) if isinstance(part, basestring) or isinstance(part, datetime.datetime) else part, item))
# show the result
result = cur.fetchall()
for row in result:
print row_tuple(row)
# close the cursor and connection
cur.close()
conn.close()
@dtrillo

This comment has been minimized.

Copy link

dtrillo commented Jan 21, 2014

Thanks for the example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.