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

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 2 de Abr. de 2016
Editada: Geoff Hayes el 2 de Abr. de 2016
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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 2 de Abr. de 2016

Comentada:

el 2 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by