Python Basics

Connect MS Access database in python (pyodbc)

MS access is also used as database to store and update data. In python projects we can use ms access as database and for that pyodbc library is required.

Install pyodbc library

Assuming you have prior known of python and library installation, run the following command in your terminal or command prompt.

pip install pyodbc

It will take couple of minutes and installs pyodbc in to the system.

Connect MS Access Database using python

Following is the python code to connect MS Access Database and fetch data.

import pyodbc

conn = pyodbc.connect(r’Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://PythonProjects/DBTutorial/msconnection.accdb;’)

cursor = conn.cursor()

cursor.execute(‘select * from employee_table’)

for row in cursor.fetchall():

print (row)