How can I read a .mdb file from MATLAB?

34 views (last 30 days)
Justin
Justin on 31 Oct 2012
Edited: Walter Roberson on 2 Jun 2015
I am trying to read a .mdb file from MATLAB.
This is my system's configuration:
Operating System: Windows Server 2008 R2 (64 bit)
MATLAB version: R2012b (64 bit)
MS Access version: MS Access 2003 (32 bit)
And here is my code:
% Specify the location of the database.
dbpath = '..\Data\myData.mdb';
% Create the connection URL.
conurl = ['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};' 'DBQ=' ...
dbpath];
% Connect to the database.
con = database('','','','sun.jdbc.odbc.JdbcOdbcDriver',conurl);
% Fetch cluster map from the database.
e = exec(con,'SELECT * FROM Cluster_Map ORDER BY Cluster_Map.CELL ASC');
e = fetch(e);
I get an error saying:
Undefined function 'fetch' for input arguments of type 'struct'.
Error in
e = fetch(e);
When I write the following:
con.message
This is the output:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Does anyone know how I can resolve this issue?
Is the issue because of my system's configuration, or am I missing a driver?
  1 Comment
Justin
Justin on 31 Oct 2012
I think I may be able to resolve the issue by installing a 64 bit version of MS Access, but am not sure. I would also prefer a cheaper alternative to resolve this issue.

Sign in to comment.

Answers (1)

Ryan G
Ryan G on 31 Oct 2012
You can try using the GUI first to make sure your commands are working as intended then use the Generate MATLAB file option in the file menu to generate the MATLAB code.
querybuilder
  2 Comments
Justin
Justin on 31 Oct 2012
Thanks for this suggestion. I tried using querybuilder to do what you said, but when I try to "Define ODBC datasource" I cannot see the MS Access .mdb driver required....so I cannot choose a driver for which to set up the data source. I can only see the SQL Server driver. I think the problem is because my Access is 32 bit and the drivers are invisible to my 64 bit version of MATLAB. Does this make sense, or is the problem something else?
Thanks.
Ryan G
Ryan G on 1 Nov 2012
If you have SMS you can download the 32-bit version of MATLAB from this site to get your data. You may still be able to get the 32 bit version without SMS, but I'm not sure how that would work. However, I really don't know how the bit-ness matters in this particular case.
Other options may include exporting to excel and reading as an excel file.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!