What are the possible ways and the best ways to return column names of a table in a Sqlite database in MATLAB? JDBC driver is used. Thanks.
1 Answer
You can query sqlite this: PRAGMA table_info(name_of_your_table);. It will give you information of all columns.
Example:
% Assuming your JDBC driver is already added to your java path
% create connection to database file
conn = database('', '', '', 'org.sqlite.JDBC', 'jdbc:sqlite:C:\your_db.sqlite');
cursor = exec(conn, 'PRAGMA table_info(name_of_your_table);');
cursor = fetch(cursor);
To output the column names, it is little different depending on used DataReturnFormat (Matlab Documentation)
- Cellarray (default)
% When DataReturnFormat is cellarray
cursor.Data(:,2) % returns table column names
- table, dataset or structure
% When DataReturnFormat is table, dataset or structure
cursor.Data.name