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

    %% Reset |DatabaseDatastore| Object to Initial State
% 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 when using the |read| function.

sqlquery = 'select * from airlinesmall';

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

%%
% Read data from the start of the data set.

read(dbds)

%%
% |read| returns the first 10 records in the data set. 

%%
% Reset the |DatabaseDatastore| object to the state where no data has been
% read from it. Resetting allows re-reading from the same
% |DatabaseDatastore| object.

reset(dbds)

%%
% Read data from the start of the data set.

read(dbds)

%%
% |read| again returns the first 10 records in the data set. 

%%
% Close the |DatabaseDatastore| object and the database connection.
close(dbds)