close
Close and invalidate database and driver resource utilizer
Syntax
Description
Examples
Connect to a Microsoft® SQL Server® database and verify the database connection. Then, import data from the database into MATLAB®. Determine the highest unit cost among the retrieved products in the table. Close the database connection.
Create an ODBC database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The database contains the table productTable
.
datasource = 'MS SQL Server Auth'; conn = database(datasource,'','');
Check the database connection. If the Message
property is empty, the connection is successful.
conn.Message
ans = []
Select all data from productTable
and sort it by the product number. data
is a table containing the imported data that results from executing the SQL SELECT
statement.
selectquery = 'SELECT * FROM productTable ORDER BY productNumber';
data = select(conn,selectquery);
Display the first three rows of data.
data(1:3,:)
ans = 3×5 table productNumber stockNumber supplierNumber unitCost productDescription _____________ ___________ ______________ ________ __________________ 1 4.0035e+05 1001 14 'Building Blocks' 2 4.0031e+05 1002 9 'Painting Set' 3 4.01e+05 1009 17 'Slinky'
Determine the highest unit cost in the table.
max(data.unitCost)
ans = 24
Close the database connection.
close(conn)
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 close it.
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 retrieves all data from the airlinesmall
table.
sqlquery = "select * from airlinesmall";
dbds = databaseDatastore(conn,sqlquery);
Close the DatabaseDatastore
object and the database connection.
close(dbds)
Input Arguments
Database and driver resource utilizer, specified as one of the objects described in this table.
Object Argument Name | Object Name | Object Description | Object Creation Function |
---|---|---|---|
|
| Create a connection between an installed database and MATLAB®. For details, see Connect to Database. | |
|
| Create a connection to a type of datastore for working with large data. |
connection
objects andDatabaseDatastore
objects remain open until you close them using theclose
function. Always close these objects when you finish using them.Executing
close
with aDatabaseDatastore
object releases the MATLAB resources associated with theconnection
object.
Note
When you close the MATLAB session, MATLAB closes open DatabaseDatastore
objects and
connections. However, the database might not free up the connections.
Consult your database administrator about the remaining
connections.
Version History
Introduced before R2006a
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)