Database Programming with Python

Tim Roberts timr at probo.com
Sun Feb 11 18:24:40 EST 2007


Finger.Octopus at gmail.com wrote:
>
>I wanted to connect Python to Ms-Access database using ADO or ODBC. I
>have Python 2.5 and on mxODBC site, it has no higher version build
>than 2.4. Moreoever, mxODBC is required for ADODB.
>Can anyone guide me on this what should I do to make it work on Python
>2.5? I have python 2.5 running on server.

You don't actually need mxODBC to use ADODB.  As long as you have the
pywin32 extensions, you have what you need.

import win32com.client
conn = win32com.client.Dispatch('ADODB.Connection')
conn.Open( "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=xxxxx.mdb" )
cmd = win32com.client.Dispatch('ADODB.Command')
cmd.ActiveConnection = conn

cmd.CommandText = "SELECT firstname,lastname FROM users;"
rs = cmd.Execute()[0]
while not rs.EOF:
    # Use elements of rs
    rs.MoveNext()

There are samples on the web.  Google should help.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list