www.gusucode.com > database 案例源码程序 matlab代码 > database/CreateDatabaseDatastoreObjectExample.m
%% Create |DatabaseDatastore| Object % 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|. sqlquery = 'select * from airlinesmall'; dbds = databaseDatastore(conn,sqlquery) %% % |databaseDatastore| executes the SQL query. |dbds| contains % these properties: %% % * Database connection object % * Executed SQL query % * List of column names from the executed SQL query % * Maximum number of records to read from the executed SQL query %% % Display the database connection property |Connection|. dbds.Connection %% % The |Message| property is blank when the database connection is % successful. %% % Close the |DatabaseDatastore| object and the database connection. close(dbds)