how to import specific cell(s) from table of database to Matlab?

2 次查看(过去 30 天)
Hi,
I have the database toolbox, and I am trying to import the information that is contained in specific cells of a table from the database to Matlab. I have tried several things, among others:
if true
% conn = database('myfirstsource', '', '');
setdbprefs('DataReturnFormat','cellarray');
curs = exec(conn, 'select * from userPassword');
columnnames(curs);
entries=curs.Data(:,1)
end
But it does not work. what i have returned is:
curs =
Attributes: []
Data: 0
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'select * from userPassword'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 sun.jdbc.odbc.JdbcOdbcResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 sun.jdbc.odbc.JdbcOdbcStatement]
Fetch: 0
ans =
[]
entries =
0
below is what is the link to the table in the database. <http://tinypic.com/r/5obb5f/6>
Why is the above code not returning the cells in the table? What am I missing?
Please help.
Thank you.
  1 个评论
MatlabFan
MatlabFan 2013-4-7
I figured it out. I needed to place a fetch statement after the execution statement. That is, right after the exec statement, i needed to write:
curs=fetch(curs)
That problem is solved.
Now, I would like to update the content of a specific cell in a table in the database. I tried using:
colnames={'Password'};
exdata='NewPassword';
fileSelected='BobSpreadsheet.xlsx';
update(conn, 'userPassword', colnames, exdata, ...
'where Username =', fileSelected)
The problem is that instead of updating the password where Username = BobSpreadsheet.xlsx, it creates a new row with Username= BobSpreadsheet.xlsx and Password=NewPassword.
How do I update the password for BobSpreadsheet.xlsx without creating a new row ?
Any idea is welcome.
Thanks.

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by