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

 Accepted Answer

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 Comments

Thank you very much Geoff Hayes, it's really solved
Glad it worked out!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!