Error importing sqlite database from autogenerated script
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
i'm a little new to matlab and am having a bit of trouble with the database explorer.
i cant seem to run the import data auto-generated script without an error coming up even if it's so simple. connection works and i can even import the data manually through the UI. but each time i try the generated script, this happens:
Script:
% Auto-generated by MATLAB Version 9.8 (R2020a) and Database Toolbox Version 9.2.1 on 19-Feb-2021 10:24:44
%% Make connection to database
conn = database('articaresLite_v2','','');
%Set query to execute on the database
query = ['SELECT * ' ...
'FROM UserExtendedModel'];
%% Execute query and fetch results
data = fetch(conn,query);
%% Close connection to database
close(conn)
%% Clear variables
clear conn query
>>UserExtMdl %this is the script's name
Error using UserExtMdl (line 17)
JDBC Driver Error: Error parsing date
Does anyone know what to do to get it working via script?
Antworten (1)
Sai Sumanth Korthiwada
am 20 Dez. 2022
Hi Gur Sevak,
There are two workarounds for this issue.
1. Using the ‘select’ Function
You can use the same connection, but alter your code to use the "select" function which will fetch the results from the database connection. The code should look like this:
>> conn = database(...);
>> selectquery = 'select * from myTable';
>> results = select(conn, selectquery);
>> close(conn);
Refer to the following documentation link for more information about "select" function: https://in.mathworks.com/help/releases/R2020a/database/ug/select.html
2. Using the ‘fetch’ Function
You can also use the "fetch" function which will fetch the results from the database connection. The code should look like this:
>> conn = database(...);
>> sqlquery = 'select * from myTable';
>> results = fetch(conn, sqlquery);
>> close(conn);
Refer to the following documentation link for more information about "fetch" function: https://in.mathworks.com/help/releases/R2020a/database/ug/database.odbc.connection.fetch.html
Hope this resolves your issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!