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

Thank you very much Geoff Hayes, it's really solved
Geoff Hayes
Geoff Hayes 2016년 4월 2일
Glad it worked out!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2016년 4월 2일

댓글:

2016년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by