Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyodbc
- db_file = r'''C:x.mdb'''
- user = 'admin'
- password = ''
- odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;UID=%s;PWD=%s' %
- (db_file, user, password)
- # Or, for newer versions of the Access drivers:
- odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;UID=%s;PWD=%s' %
- (db_file, user, password)
- conn = pyodbc.connect(odbc_conn_str)
- import odbc
- def get_pg_ver(db_alias):
- connection = odbc.odbc(db_alias)
- try:
- cursor = connection.cursor()
- cursor.execute('SELECT version()')
- for row in cursor.fetchall():
- print row[0]
- finally:
- connection.close()
- get_pg_ver('odbc_name/user/passwd')
- import pypyodbc
- pypyodbc.win_create_mdb( "D:\Your_MDB_file_path.mdb" )
- import adodbapi
- database = "db1.mdb"
- constr = 'Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s' % database
- tablename = "address"
- # connect to the database
- conn = adodbapi.connect(constr)
- # create a cursor
- cur = conn.cursor()
- # extract all the data
- sql = "select * from %s" % tablename
- cur.execute(sql)
- # show the result
- result = cur.fetchall()
- for item in result:
- print item
- # close the cursor and connection
- cur.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement