From: fiza khalid on
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.
From: Adrian Cherry on
"fiza khalid" <princess.2050(a)hotmail.com> wrote in message <i0sabb$3rk$1(a)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
From: fiza khalid on
"Adrian Cherry" <adrian.cherry(a)baesystems.com> wrote in message <i0sfeg$15o$1(a)fred.mathworks.com>...
> "fiza khalid" <princess.2050(a)hotmail.com> wrote in message <i0sabb$3rk$1(a)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.
From: Faraz Afzal on
"fiza khalid" <princess.2050(a)hotmail.com> wrote in message <i14cm7$d7j$1(a)fred.mathworks.com>...
> "Adrian Cherry" <adrian.cherry(a)baesystems.com> wrote in message <i0sfeg$15o$1(a)fred.mathworks.com>...
> > "fiza khalid" <princess.2050(a)hotmail.com> wrote in message <i0sabb$3rk$1(a)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
 | 
Pages: 1
Prev: lasso tool
Next: Advance input command?