简体   繁体   中英

How do I access a .mdb file from python?

I have my database in msacess 2000 .mdb format which I downloaded from the net and now I want to access that database from my program which is a python script. Can I call tables from my programs?? it would be very grateful if anyone of you please suggest me what to do

For whoever pass by, another option is using mdbtools - which can export the MDB database to a re-usable format, like CSV- check: http://mazamascience.com/WorkingWithData/?p=168

If you don't need to update the mdb file, just to import legacy data, doing something akin to the recipe on the link above is easier than get pyodbc working properly and, it does not require access to a Windows machinne

If you work on Windows, then you can use ODBC and use odbc module (ActiveState Python has it by default, this is part of win32 extensions), or pyodbc module. Have a look at answers to: How to connect pyodbc to an Access (.mdb) Database file

If you use Jython you can use JDBC-ODBC bridge:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
db = DriverManager.getConnection('jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Nwind.mdb', usr, passwd)

Create an ODBC DSN wit hthis MDB. Python can access ODBC data sources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM