Error importing sqlite database from autogenerated script

1 次查看(过去 30 天)
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?

回答(1 个)

Sai Sumanth Korthiwada
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.

类别

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

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by