MATLAB: How to use Database Toolbox to query ACCDB/MDB file programmatically without JDBC/ODBC bridge on Windows

accdbbridgeDatabase Toolboxjdbc/odbcmdbodbc

Starting R2017b, MATLAB Database Toolbox no longer supports JDBC/ODBC bridge because MATLAB starts using JRE version 8. How can I query ACCDB/MDB file on Windows with Database Toolbox?

Best Answer

Please consider adding/removing the ODBC data source using command line options in Windows. Please refer to the following page from Microsoft for commands such as 'odbcconf' in command prompt or 'Add-OdbcDsn' in PowerShell:
Since 'odbcconf' is not recommended by Microsoft, please find the following example of using '<https://www.mathworks.com/help/matlab/ref/system.html system>' command in MATLAB to execute PowerShell command 'Add-OdbcDsn' with the following:
>> dbqfilepath = strcat("'dbq=", filepath, "'");
>> dbsource = strcat("powershell;Add-OdbcDsn -Name 'dbdemo' -DriverName 'Microsoft Access Driver (*.mdb, *.accdb)' -DsnType 'User' -Platform '64-bit' -SetPropertyValue ", dbqfilepath);
>> system(dbsource);
The above would help adding the datasource to ODBC and you may then use '<https://www.mathworks.com/help/database/ug/database.html database>' command for native ODBC connection.
To remove the data source, please refer to the following page from Microsoft for the 'Remove-OdbcDsn' PowerShell command:
An example command would look like the following:
system("powershell;Remove-OdbcDsn -Name 'dbdemo' -DsnType 'User' -Platform '64-bit'");