How to access the MDB database via Python script in Linux

Source: Internet
Author: User
Tags ini mdb database odbc python script


This article mainly introduces the method of accessing the MDB database through Python script in Linux, this article is based on the Linux system of the Debian Department, the friend who needs it can refer to the



In the Linux system to connect the MDB database, directly connected, the MDB default driver does not recognize the non-Windows path, so you can not use the normal connection method




Driver={microsoft Access DRIVER (*.mdb)};D Bq=c:dirfile.mdb


Installation



Here we need to use some libraries to implement the third party driver



We need to install these packages: Mdbtools, UNIXODBC, LIBMDBODBC



If you are not able to find Libmdbodbc in a deb-enabled system, add the following path to the list of software sources



Deb Http://ftp.de.debian.org/debian Squeeze Main



LIBMDBODBC can be installed after the source is updated



Configuration



After installing the required packages, you need to do some configuration to support the LIBMDBODBC driver



The code is as follows:



/etc/odbcinst.ini



[MDBTOOLSODBC]



Description = MDB Tools ODBC



Driver =/usr/lib/libmdbodbc.so.0



Setup =



FileUsage =



CPTimeout =



Cpreuse =



/etc/odbc.ini or ~/.odbc.ini.



The code is as follows:



[Test]



Description = Microsoft Access Try DB



Driver = Mdbtoolsodbc



Database =/path/to/mdb/file/test.mdb



Servername = localhost



Username =



Password =



Port = 5432



Code



Once the data source is configured, it can be used in any application that supports ODBC access, as an example of PYODBC




#-*-coding:utf-8-*-

Import Pyodbc

 conn = Pyodbc.connect (' dsn=test '); 

cursor = Conn.cursor () cursor.execute (' select * from ' province ') for row in Cursor.fetchall (): Print row. Name


Note: If the operation name of the Chinese table or field, you need to include it in double quotes, otherwise there will be errors, of course, the table name into Chinese so two of the practice, or not recommended use of the



Pyodbc is a very good library, the API is also very useful, but not good for Chinese support, it does not default to Unicode processing data, so for Chinese-related applications, coding problems everywhere, had to slowly toss.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.