How to fetch data from table using where condition ????
7 views (last 30 days)
Show older comments
Ganesan Deivakkannu
on 20 Apr 2014
Commented: Ganesan Deivakkannu
on 21 Apr 2014
I have a code like below
p = 'C:\Program Files\MATLAB\R2011a\java\jarext\mysql-connector-java-5.1.20-bin.jar';
if ~ismember(p,javaclasspath)
javaaddpath(p)
end
conn = database('outputadapter','root','litham','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/outputadapter');
setdbprefs('DataReturnFormat','cellarray');
curs = exec(conn,'SELECT value,signalID FROM measurement')
curs = fetch(curs)
cur=curs.Data;
Code work perfectly(To fetch the data from database)
I want to fetch the data from database in particular singnalID values, code below
p = 'C:\Program Files\MATLAB\R2011a\java\jarext\mysql-connector-java-5.1.20-bin.jar';
if ~ismember(p,javaclasspath)
javaaddpath(p)
end
conn = database('outputadapter','root','litham','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/outputadapter');
setdbprefs('DataReturnFormat','cellarray');
curs = exec(conn, 'SELECT ALL Value FROM measurement WHERE signalID =D97C6D5A-B6A9-4259-84D7-1FE5A0F6147D');
curs = fetch(curs);
cur=curs.Data;
Code wont work,pls give some idea how use the where condition in MATLAB
1 Comment
dpb
on 20 Apr 2014
"Know "nuthink" about Matlab database connection and almost that much about SQL, but I'd guess it's in the formulation of the query where the problem is rather than anything specifically to do with Matlab.
Can you form the query and return desired results directly w/o Matlab first?
What's the symptom -- "won't work" is NEVER sufficient explanation for a problem.
Accepted Answer
the cyclist
on 20 Apr 2014
As dpb mentions in his comment, this is not really a MATLAB problem, but a SQL problem.
It looks like signalID is text, so in place of
'SELECT ALL Value FROM measurement WHERE signalID =D97C6D5A-B6A9-4259-84D7-1FE5A0F6147D'
you probably want
'SELECT ALL Value FROM measurement WHERE signalID = ''D97C6D5A-B6A9-4259-84D7-1FE5A0F6147D'''
More Answers (0)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!