readall
Read all data in DatabaseDatastore
Syntax
Description
Examples
Read All Data in DatabaseDatastore
Object
Create a database connection using a JDBC driver. To create this connection, you must configure a JDBC data source. For more information, see the
function. Then, create a configureJDBCDataSource
DatabaseDatastore
object and read all 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);
Read all data in the DatabaseDatastore
object.
data = readall(dbds);
data
contains the query results.
Display the first three rows of query results.
data(1:3,:)
ans = 3×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 ____ _____ __________ _________ _______ __________ _______ __________ _____________ _________ _______ _________________ ______________ _______ ________ ________ ______ _____ ________ ______ _______ _________ ________________ ________ ____________ ____________ ________ _____________ _________________ 1987 10 28 3 1140 1140 1212 1215 'US' 262 'NA' 32 35 'NA' -3 0 'CLE' 'PIT' 105 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA' 1987 10 9 5 1155 1155 1250 1300 'US' 282 'NA' 55 65 'NA' -10 0 'ROC' 'LGA' 254 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA' 1987 10 22 4 715 715 807 803 'US' 304 'NA' 52 48 'NA' 4 0 'DTW' 'PIT' 201 'NA' 'NA' 0 'NA' 0 'NA' 'NA' 'NA' 'NA' 'NA'
Close the DatabaseDatastore
object and the database connection.
close(dbds)
Input Arguments
dbds
— Datastore containing data in database
DatabaseDatastore
object
Datastore containing data in a database, specified as a DatabaseDatastore
object
created using the databaseDatastore
function.
Output Arguments
data
— Query results
table
Query results, returned as a table of the records in the data
set. Executing the SQL statement specified in the Query
property
of the DatabaseDatastore
object creates the data
set.
Version History
Introduced in R2014b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)