preview - Return subset of data from DatabaseDatastore - MATLAB (original) (raw)
Main Content
Return subset of data from DatabaseDatastore
Syntax
Description
[data](#bucvha6-data) = preview([dbds](#bucvha6%5Fsep%5Fshared-dbds))
returns the first eight rows of data from the DatabaseDatastore
object dbds
without changing its current position.
Note
preview
returns data as a table only.preview
ignores database preference settings for data return formatting.
If there is no data to read from the query, preview
throws an error.
Examples
Create a database connection using a JDBC driver. To create this connection, you must configure a JDBC data source. For more information, see the [configureJDBCDataSource](configurejdbcdatasource.html)
function. Then, create a DatabaseDatastore
object and preview the data stored in the object.
Create a database connection to the JDBC data source MSSQLServerJDBCAuth
. This data source configures a JDBC driver to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password.
datasource = "MSSQLServerJDBCAuth"; username = ""; password = ""; conn = database(datasource,username,password);
Create a DatabaseDatastore
object using the database connection and an SQL query. This SQL query reads all data from the airlinesmall
table.
sqlquery = 'select * from airlinesmall';
dbds = databaseDatastore(conn,sqlquery);
Preview the first eight records in the data set returned by executing the SQL query in the DatabaseDatastore
object.
ans =
8×29 table
Year Month DayofMonth DayOfWeek DepTime CRSDepTime ArrTime CRSArrTime UniqueCarrier FlightNum TailNum ActualElapsedTime CRSElapsedTime AirTime ArrDelay DepDelay Origin Dest Distance TaxiIn TaxiOut Cancelled CancellationCode Diverted CarrierDelay WeatherDelay NASDelay SecurityDelay LateAircraftDelay
____ _____ __________ _________ _______ __________ _______ __________ _____________ _________ ________ _________________ ______________ _______ ________ ________ ______ _____ ________ ______ _______ _________ ________________ ________ ____________ ____________ ________ _____________ _________________
1990 9 11 2 1810 1812 1939 1930 'AA' 1426 'NA' 89 78 'NA' 9 -2 'RST' 'ORD' 268 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
1990 10 27 6 1353 1355 1634 1640 'US' 112 'NA' 161 165 'NA' -6 -2 'TPA' 'SYR' 1104 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
1990 10 23 2 1057 1055 1205 1155 'US' 1621 'NA' 68 60 'NA' 10 2 'ROC' 'EWR' 246 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
1990 10 8 1 1515 1440 1609 1535 'NW' 749 'NA' 54 55 'NA' 34 35 'MSP' 'FSD' 197 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
1990 10 19 5 1130 1120 1203 1154 'UA' 369 'NA' 93 94 'NA' 9 10 'BUF' 'ORD' 473 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
1990 10 12 5 1755 1733 1858 1820 'DL' 590 'NA' 63 47 'NA' 38 22 'BOS' 'BGR' 201 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
2001 11 22 4 1345 1355 1530 1549 'MQ' 4982 '#NAME?' 105 114 '90' -19 -10 'JAX' 'MIA' 334 '8' '7' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
2001 11 26 1 2105 2110 2209 2237 'AA' 1947 'N3BäA1' 64 87 '47' -28 -5 'SFO' 'LAX' 337 '6' '11' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
Close the DatabaseDatastore
object and the database connection.
Input Arguments
Datastore containing data in a database, specified as a DatabaseDatastore
object created using the databaseDatastore function.
Output Arguments
Query results, returned as a table of the first eight records in the data set. Executing the SQL statement specified in the Query
property of the DatabaseDatastore
object creates the data set.
If there is no data to read from the query, preview
throws an error.
Version History
Introduced in R2014b