Created
July 7, 2017 10:30
-
-
Save pbdanny/f75ffbf37bc8e66014371bf6460e1ddf to your computer and use it in GitHub Desktop.
Use JayDeBeAPI with JDBC connect to MS Access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import jaydebeapi | |
| # Initiate Java runtiome file location | |
| ucanaccess_jars = [ | |
| "/Users/Danny/Documents/UCanAccess-4.0.2-bin/ucanaccess-4.0.2.jar", | |
| "/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/commons-lang-2.6.jar", | |
| "/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/commons-logging-1.1.1.jar", | |
| "/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/hsqldb.jar", | |
| "/Users/Danny/Documents/UCanAccess-4.0.2-bin/lib/jackcess-2.1.6.jar", | |
| ] | |
| # classpath = $PATH$ parameters for Java runtime file location | |
| classpath = ":".join(ucanaccess_jars) | |
| # Initate connection to MS Access files | |
| cnxn = jaydebeapi.connect( | |
| "net.ucanaccess.jdbc.UcanaccessDriver", | |
| "jdbc:ucanaccess:///Users/Danny/Share Win7/2017OSSDatabase.accdb", | |
| ["", ""], | |
| classpath | |
| ) | |
| # From connection initiate cursor | |
| crsr = cnxn.cursor() | |
| # Run Query | |
| crsr.execute("SELECT * FROM Region_KTC") | |
| # Fetch Query result | |
| for row in crsr.fetchall(): | |
| print(row) | |
| # Close cursor | |
| crsr.close() | |
| # Close connection | |
| cnxn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment