www.gusucode.com > database 案例源码程序 matlab代码 > database/RetrieveDatabaseDatastoreDataExample.m

    %% Read Data
% Using a JDBC driver, create a database connection |conn| to a
% Microsoft(R) SQL Server(R) database with Windows(R) authentication.
% Specify a blank user name and password. The code assumes that you
% are connecting to a database |toy_store|, a database server |dbtb04|, and
% port number |54317|.

conn = database('toy_store','','','Vendor','Microsoft SQL Server', ...
    'Server','dbtb04','PortNumber',54317,'AuthType','Windows');

%% 
% Create a |DatabaseDatastore| object |dbds| using the database connection
% |conn| and SQL query |sqlquery|. This SQL query retrieves all data from
% the table |airlinesmall|. Specify reading a maximum of 10 records
% from the executed SQL query.

sqlquery = 'select * from airlinesmall';

dbds = databaseDatastore(conn,sqlquery,'ReadSize',10);

%%
% Read the data in the |DatabaseDatastore| object |dbds|.

data = read(dbds)

%%
% |data| contains the query results.

%%
% Close the |DatabaseDatastore| object and database connection.

close(dbds)