0

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 1

1

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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.