insert variable value in mysql using Matlab

how to insert the variable value in mysql using Matlab? I have tried this program, but nothing happen in my mysql database
a=1.1;
b=1.2;
c=1.3;
conn=database('citra', 'root', '', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost/');
r=exec(conn, 'insert into histogram(mean, varians, skewness) values {'a','b','c'}');

 Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 2 Apr. 2016
Bearbeitet: Geoff Hayes am 2 Apr. 2016

0 Stimmen

rio - I don't have the Database Toolbox so I can't tell you for sure what is wrong, but I think that your SQL statement is incorrect in that it is not being populated with the values for the variables a, b, and c. I think that you need to use sprintf to create the command as
sqlCommand = sprintf('insert into histogram (mean,variance,skewness) values (%f,%f,%f)',a,b,c);
With the above, the sqlCommand string becomes
insert into histogram (mean,variance,skewness) values (1.100000,1.200000,1.300000)
Note that I have changed the second column to be variance which may be incorrect so you will need to verify that all three columns are correct. Also verify the syntax for the statement to ensure that it is suitable for your mySQL database.
Then, you can use this command string as
conn=database('citra', 'root', '', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost/');
r=exec(conn, sqlCommand);

2 Kommentare

rio hartanto
rio hartanto am 2 Apr. 2016
Thank you very much Geoff Hayes, it's really solved
Geoff Hayes
Geoff Hayes am 2 Apr. 2016
Glad it worked out!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by