from timetable to mysql database

4 ビュー (過去 30 日間)
Marco Laiolo
Marco Laiolo 2024 年 3 月 18 日
コメント済み: Marco Laiolo 2024 年 3 月 29 日
Hi all,
I routinely automatic timetable every X minutes at the end of data processing all with matlab 2023b. I have a mysql database that, currently, i update setting colheaders and alllcolumn variables (double or string or datetime).
I see that sqlwrite don't work with timetable; someone know other function or strategy to write timetable (with colheader) directly in a already created mysql table that have the same column and header name of the timetable?
Thanks
Marco

回答 (1 件)

Samay Sagar
Samay Sagar 2024 年 3 月 25 日
As mentioned in the MathWorks documentation, “sqlwrite” supports only insertion of “table” data type in a database. However, you can insert a “timetable” in SQL database by employing a workaround by converting your “timetable” to “table” using “timetable2table” function. After converting your timetable to a table, ensure the column names exactly match those in your MySQL table. If your timetable includes a “Time” column (which is automatically created during the conversion), and your MySQL table uses the same column name for time/date data, you're all set. If not, you might need to adjust the column names in your MATLAB table to align with your MySQL schema.
Read more about “timetable2table” and “sqlwrite” here:
  2 件のコメント
Marco Laiolo
Marco Laiolo 2024 年 3 月 28 日
Thank you very much , Samay...great and it works!
Marco Laiolo
Marco Laiolo 2024 年 3 月 29 日
However, it seems that if in the TABLE there is an already write row (with the same) the command sqlwrite don't work
this tis the message
JDBC Error: Duplicate entry .... for key 'time' (my firstrow after id)
even if I set "unique" on my variable time in mysql db.It's a my problem or someone know this.
Thanks a lot

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

Community Treasure Hunt

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

Start Hunting!

Translated by