close
Close and invalidate database and driver resource utilizer
Syntax
Description
Examples
Closeconnection
Object
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.
创建一个n ODBC database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The database contains the tableproductTable
.
datasource ='MS SQL Server Auth';conn = database(datasource,'','');
Check the database connection. If theMessage
property is empty, the connection is successful.
conn.Message
ans = []
Select all data fromproductTable
and sort it by the product number.data
is a table containing the imported data that results from executing the SQLSELECT
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)
CloseDatabaseDatastore
Object
创建一个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 aconfigureJDBCDataSource
DatabaseDatastore
object and close it.
创建一个database connection to the JDBC data sourceMSSQLServerJDBCAuth
. 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";用户名="";password ="";conn = database(datasource,username,password);
创建一个DatabaseDatastore
object using the database connection and an SQL query. This SQL query retrieves all data from theairlinesmall
table.
sqlquery ="select * from airlinesmall";dbds = databaseDatastore(conn,sqlquery);
Close theDatabaseDatastore
object and the database connection.
close(dbds)
Input Arguments
object
—Database and driver resource utilizer
connection
object|DatabaseDatastore
object
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 |
---|---|---|---|
|
|
创建一个connection between an installed database and MATLAB®. For details, seeConnect to Database. |
|
|
|
创建一个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 openDatabaseDatastore
对象和连接。然而,数据库米格ht not free up the connections. Consult your database administrator about the remaining connections.
版本History
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
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)