connect database to matlab

1 次查看(过去 30 天)
kareem hassan
kareem hassan 2020-7-3
i have database created in mysql and i want to use it in matlab so i used matlab connector ODBC
then i used this code to item file in my database
conn = database('kk2','root','');
curs = exec(conn,'INSERT INTO `item`(`name`) VALUES (`pen`)');
but nothing happend and ther is no error in command window

回答(1 个)

Piyush Kumar
Piyush Kumar 2024-9-27
If nothing happens and there are no errors, it might mean that the data was inserted successfully but you didn’t receive any confirmation. To ensure everything is working as expected, you can verify the insertion by querying the database to check if the new data is present.
I will suggest to add some condition statements to make sure that the execution was successful -
1.Check Database connection: Ensure that the connection to the database is successful.
conn = database('kk2', 'root', '');
if isopen(conn)
disp('Connection successful');
else
disp(['Connection failed: ' conn.Message]);
end
2. Execute the Query Manually: Before using the query in your script, manually execute it in the MySQL command line or a database management tool to ensure it works as expected.
3. In the script, print the output of "exec" to verify the successful query execution.

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

标签

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by