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'}');

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 4 月 2 日
編集済み: Geoff Hayes 2016 年 4 月 2 日

0 投票

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 件のコメント

rio hartanto
rio hartanto 2016 年 4 月 2 日
Thank you very much Geoff Hayes, it's really solved
Geoff Hayes
Geoff Hayes 2016 年 4 月 2 日
Glad it worked out!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by