- “contains" function: https://in.mathworks.com/help/matlab/ref/string.contains.html
- “database": https://in.mathworks.com/help/database/ug/database.html
database catalog is a full path not a word
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to use 'SQL USE CLAUSE' to change database catalog based on Matlab and access 2013, but it seems dificult to realize when catalog is a full path. how can I do or change my codes?
connin = database('inputmatlab','','');
MSin=connin.Message;
B=connin.Catalogs;
sqlquery = 'Use C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb';
A=exec(connin,sqlquery);
The 'A=exec(connin,sqlquery)' is a error.
close(connin);
The connin information is :
DataSource: 'inputmatlab'
UserName: ''
Message: ''
Type: 'ODBC Connection Object'
Database Properties:
AutoCommit: 'on'
ReadOnly: 'off'
LoginTimeout: -1
MaxDatabaseConnections: -1
Catalog and Schema Information:
DefaultCatalog: 'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb'
Catalogs: {'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb', ' ...\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\HINDAWI3.accdb', 'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\MDPI3.accdb' ... and 6 more}
Schemas: {}
Database and Driver Information:
DatabaseProductName: 'ACCESS'
DatabaseProductVersion: '12.00.0000'
DriverName: 'ACEODBC.DLL'
DriverVersion: 'Microsoft Access database engine'
댓글 수: 0
답변 (1개)
Ravi
2023년 11월 27일
Hi PP Wei,
I assume you want to search for a catalog based on a single word instead of using the complete path for that catalog.
One possible solution to your question is, you can obtain the list of catalogs from the connection object and search for the word in every catalog path. If the catalog path contains the word you are searching for, then use that catalog present at that index in your SQL USE query. Please note that, the word contains the extension of the database. Example, word = “ACSE3.accdb”.
Please refer to the code snippet that illustrates the workflow mentioned above:
db = '';
found = false;
isPresent = contains(catalogs, word);
for i = 1:length(catalogs)
if(isPresent(i))
disp(catalogs{i});
db = catalogs{i};
found = true;
end
end
if ~found
disp('file not found');
else
query = "use " + db;
end
Please refer to the below documentation to learn more about:
Hope this helps.
Thanks,
Ravi Chandra
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!