Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Database connectivity

Subject: Database connectivity

From: fiza khalid

Date: 5 Jul, 2010 09:58:03

Message: 1 of 4

Hi everyone,
I want to do a database connectivity from Mat lab to Microsoft Access from where i can import and export data.can anyone help me?plz do reply me how can i do that?
thnx in advance.

Subject: Database connectivity

From: Adrian Cherry

Date: 5 Jul, 2010 11:25:04

Message: 2 of 4

"fiza khalid" <princess.2050@hotmail.com> wrote in message <i0sabb$3rk$1@fred.mathworks.com>...
> Hi everyone,
> I want to do a database connectivity from Mat lab to Microsoft Access from where i can import and export data.can anyone help me?plz do reply me how can i do that?
> thnx in advance.

There are a couple of options, one is to create a java class with the JDBC driver. This is useful if you want to switch later to another database, mySQL etc.

If it's just Access you're going to use then you can do it with actxserver

~~~~~~~~~~~~~~~~~~~~~~
% setup database connection
conn = actxserver('ADODB.Connection');
connString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="myAccessDatabase.mdb";User Id=;Password=;';

conn.Open(connString);

% create query
sqlQuery = 'SELECT * FROM TABLENAME WHERE ID LIKE "%32%";';

% execute query
res = conn.Execute(sqlQuery);
if res.eof,
    disp('no results found');
else
    myData = res.GetRows;
end

% close database connection
conn.Close
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This will allow you to read the data but I seem to remember there are some restrictions over what the actxserver can do. If you need full control then you might need to go down the Java JDBC route.

Regards

Adrian

Subject: Database connectivity

From: fiza khalid

Date: 8 Jul, 2010 11:27:03

Message: 3 of 4

"Adrian Cherry" <adrian.cherry@baesystems.com> wrote in message <i0sfeg$15o$1@fred.mathworks.com>...
> "fiza khalid" <princess.2050@hotmail.com> wrote in message <i0sabb$3rk$1@fred.mathworks.com>...
> > Hi everyone,
> > I want to do a database connectivity from Mat lab to Microsoft Access from where i can import and export data.can anyone help me?plz do reply me how can i do that?
> > thnx in advance.
>
> There are a couple of options, one is to create a java class with the JDBC driver. This is useful if you want to switch later to another database, mySQL etc.
>
> If it's just Access you're going to use then you can do it with actxserver
>
> ~~~~~~~~~~~~~~~~~~~~~~
> % setup database connection
> conn = actxserver('ADODB.Connection');
> connString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="myAccessDatabase.mdb";User Id=;Password=;';
>
> conn.Open(connString);
>
> % create query
> sqlQuery = 'SELECT * FROM TABLENAME WHERE ID LIKE "%32%";';
>
> % execute query
> res = conn.Execute(sqlQuery);
> if res.eof,
> disp('no results found');
> else
> myData = res.GetRows;
> end
>
> % close database connection
> conn.Close
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This will allow you to read the data but I seem to remember there are some restrictions over what the actxserver can do. If you need full control then you might need to go down the Java JDBC route.
>
> Regards
>
> Adrian
>>thnx for ur response i start doing in that manner but i am getting an error as under
??? Invoke Error, Dispatch Exception:
Source: Microsoft JET Database Engine
Description: Could not find file 'C:\Documents and Settings\FIZA\My
Documents\MATLAB\Database1.mdb'.

Error in ==> db1 at 5
conn.Open(connString);
>>my database is in the matlab directory but it is giving me error how i can correct that plz tell me.

Subject: Database connectivity

From: Faraz Afzal

Date: 8 Jul, 2010 12:34:04

Message: 4 of 4

"fiza khalid" <princess.2050@hotmail.com> wrote in message <i14cm7$d7j$1@fred.mathworks.com>...
> "Adrian Cherry" <adrian.cherry@baesystems.com> wrote in message <i0sfeg$15o$1@fred.mathworks.com>...
> > "fiza khalid" <princess.2050@hotmail.com> wrote in message <i0sabb$3rk$1@fred.mathworks.com>...
> > > Hi everyone,
> > > I want to do a database connectivity from Mat lab to Microsoft Access from where i can import and export data.can anyone help me?plz do reply me how can i do that?
> > > thnx in advance.
> >
> > There are a couple of options, one is to create a java class with the JDBC driver. This is useful if you want to switch later to another database, mySQL etc.
> >
> > If it's just Access you're going to use then you can do it with actxserver
> >
> > ~~~~~~~~~~~~~~~~~~~~~~
> > % setup database connection
> > conn = actxserver('ADODB.Connection');
> > connString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="myAccessDatabase.mdb";User Id=;Password=;';
> >
> > conn.Open(connString);
> >
> > % create query
> > sqlQuery = 'SELECT * FROM TABLENAME WHERE ID LIKE "%32%";';
> >
> > % execute query
> > res = conn.Execute(sqlQuery);
> > if res.eof,
> > disp('no results found');
> > else
> > myData = res.GetRows;
> > end
> >
> > % close database connection
> > conn.Close
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > This will allow you to read the data but I seem to remember there are some restrictions over what the actxserver can do. If you need full control then you might need to go down the Java JDBC route.
> >
> > Regards
> >
> > Adrian
> >>thnx for ur response i start doing in that manner but i am getting an error as under
> ??? Invoke Error, Dispatch Exception:
> Source: Microsoft JET Database Engine
> Description: Could not find file 'C:\Documents and Settings\FIZA\My
> Documents\MATLAB\Database1.mdb'.
>
> Error in ==> db1 at 5
> conn.Open(connString);
> >>my database is in the matlab directory but it is giving me error how i can correct that plz tell me.

Dear Fiza,

One of the two possibilities,

1. Spelling mistake,
2. Case mistake (Upper case D in Database.mdb)
3. Add this folder to your Matlab path and then try.

Regards,
Muhammad Faraz

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us