1

I was trying to connect to a Access database from matlab, by following the example given in matlab documentation

1 setdbprefs('DataReturnFormat','cellarray')
2 url = [['jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ='] dbpath];
3 con = database('','','','sun.jdbc.odbc.JdbcOdbcDriver', url);
4 sql = ['select * from ' table_name] ;
5 cursor = exec(con,sql);
6 cursor = fetch(cursor);
7 data.data = cursor.data;

I got the following error when I was requesting data from table A, at line 6, the error message was:

Error using cell
Size inputs must be integers.

Error in cursor/fetch (line 329)
                                    outCursor.Data =
                                    cell(rowLimit,
                                    numberOfColumns);

I tried fetch data from other tables in the same database, it went without problem. What might be the issue?

2 Answers 2

1

Please refer to the documentation. fetch must be called with two parameters, connection and query and it returns the result, not a cursor.

Sign up to request clarification or add additional context in comments.

2 Comments

Well, that is not completely true, fetch can be called with one argument, a cursor resulting from executing a sql query.(mathworks.com/help/database/ug/fetch.html), but your method did solve my problem! Thanks, I am upvoting for now, if no one came up with answers to why my error occur in a couple of days, I will accept your answer. :)
There is something really strange in the documentation: mathworks.de/de/help/database/ug/fetch.html mathworks.de/de/help/database/ug/database.fetch.html Sometimes I don't really understand the way the documentation is organised...
0

Ok, I still hadn't got to the bottom of this yet, but retrieving the data incrementally worked for me, by setting the preference:

setdbprefs('FetchInBatches', 'yes');
setdbprefs('FetchBatchSize', '2');

@Daniel's answer also works fine, but it is difficult to get the column headers that way (let me know if you know how, I tried using another sql query but if did not work for me)...

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.