简体   繁体   English

如何从python访问.mdb文件?

[英]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. 我有从网上下载的msacess 2000 .mdb格式的数据库,现在我想从我的程序(它是python脚本)访问该数据库。 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 对于任何经过的人,另一个选择是使用mdbtools-可以将MDB数据库导出为可重复使用的格式,例如CSV-检查: 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 如果您不需要更新mdb文件,而只是导入旧数据,则与上面链接中的配方相似,比起使pyodbc正常工作更容易,并且不需要访问Windows机器

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. 如果您在Windows上工作,则可以使用ODBC并使用odbc模块(ActiveState Python默认情况下具有它,这是win32扩展的一部分)或pyodbc模块。 Have a look at answers to: How to connect pyodbc to an Access (.mdb) Database file 看一下答案: 如何将pyodbc连接到Access(.mdb)数据库文件

If you use Jython you can use JDBC-ODBC bridge: 如果使用Jython,则可以使用JDBC-ODBC桥:

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. 使用此MDB创建ODBC DSN。 Python can access ODBC data sources. Python可以访问ODBC数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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