www.gusucode.com > database 案例源码程序 matlab代码 > database/RetrieveDatabaseDatastoreDataAndDatabaseInfoExample.m
%% Read Data and Database Information % 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| and retrieve % information |info| about the database. [data,info] = read(dbds) %% % |data| contains the query results. The structure |info| contains the % data source name |datasource| and current cursor position |offset|. %% % Close the |DatabaseDatastore| object and database connection. close(dbds)