필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
MatlabFan
MatlabFan 2013년 4월 7일
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