Home > database >  Python connection access2003
Python connection access2003

Time:09-21

Have a work for eight years xp computer, installation is weak access2003 database, want to use python access2003 database, because the system is old, database password, did not find ready-made on baidu, with some kind of, finally success, I wish to share,
A work environment: Windows xp, access2003 database, python2.7 (python3 does not support), pywin32-221. The win32 - py2.7
To install python2.7 first, then install pywin32-221. The win32 - py2.7
Second, connection code:
 # - * - coding: cp936 - * - 
The import win32com. Client
Conn=win32com. Client. Dispatch (r "ADODB. Connection")
DSN='. The Provider=Microsoft Jet. The OLEDB. 4.0. The Data Source=test. The MDB; Persist Security Info=False; The Jet OLEDB: Database Password=123456 '# test. MDB is access file, 123456 is the Database Password
Conn. Open (DSN)
Rs=win32com. Client. Dispatch (r 'ADODB. You')
Rs_name='Employee'
Rs. The Open ('/' + rs_name + ' ', conn, 1, 3)
SQL="Update" + rs_name + "Set Name='product' where ID=11" # here is the SQL statement
Conn. Execute (SQL) # executing SQL statements
Conn. Close ()


If the query, the implementation of the rs. Open has been wrong, then simply remove the square brackets, fix the problem, and the following code
 import win32com. Client 

Def listBrushCardInfo (condition) :
Conn=win32com. Client. Dispatch (r "ADODB. Connection")
DSN='. The Provider=Microsoft Jet. The OLEDB. 4.0. The Data Source=test. The MDB; Persist Security Info=False; The Jet OLEDB: Database Password=123456 '
Conn. Open (DSN)
Rs=win32com. Client. Dispatch (r 'ADODB. You')
Rs. Cursorlocation=3

Rs_name="SELECT * FROM Top 20 BrushCardInfo" + condition, "the order by the Date desc, Time desc"
# here SQL statements with mysql is a little difference, such as former article 20, with the top 20, not using limit
Rs. The Open (rs_name, conn, 1, 3)

Rs. MoveFirst ()
For x in the range (rs. RecordCount) :
If the rs. EOF:
Print "End of records"
Break
The else:
Print the rs. Fields (" Date "). The value of rs. The Fields (" Time "). The value of rs. Fields (" Name "). The value of rs. Fields (" color "). The value
Rs. MoveNext ()
Conn. Close ()
  • Related