| Database Toolbox™ | ![]() |
Connect to databases using Visual Query Builder. For more information on Visual Query Builder, see Using Visual Query Builder.
conn = database('datasourcename','username','password')
conn = database('databasename','username',...
'password','driver','databaseurl')
conn = database('datasourcename','username','password') connects a MATLAB® software session to a database via an ODBC driver and assigns the returned connection object to conn. The arguments passed to this function are as follows:
datasourcename: The data source to which you connect.
username and password are the user name and password required to connect to the database. If a user name or password are not required to connect to your database, specify empty strings for these arguments.
conn = database('databasename','username',...
'password','driver','databaseurl') connects a MATLAB software
session to a database and assigns the returned connection object to conn. The arguments passed to this function are as follows:
databasename: The name of the database to which you connect.
driver: The name of your JDBC driver.
username and password: The user name and password required to connect to the database. If a user name or password are not required to connect to your database, specify empty strings for these arguments.
databaseurl: A JDBC URL object of the form jdbc:subprotocol:subname. subprotocol is a database type, such as Oracle®. subname may contain other information used by driver, such as the location of the database and/or a port number. subname may take the form //hostname:port/databasename.
If database establishes a database connection, it returns information about the connection object, as shown in the following example:
Instance: 'SampleDB'
UserName: ''
Driver: []
URL: []
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: []
Handle: [1x1 sun.jdbc.odbc.JdbcOdbcConnection]
TimeOut: 0
AutoCommit: 'off'
Type: 'Database Object'
Connect to an ODBC data source called Pricing, specifying user name mike, and password bravo.
conn = database('Pricing', 'mike', 'bravo');
Connect to an ODBC data source SampleDB where a user name and password are not required to access the database.
conn = database('SampleDB','','');
In this example, the following arguments are passed to the database function:
oracle, the database to which you connect
scott and tiger, the required user name and password
oracle.jdbc.driver.OracleDriver, the oci7 JDBC driver name
jdbc:oracle:oci7, the URL that specifies the location of the database server
conn = database('oracle','scott','tiger',...
'oracle.jdbc.driver.OracleDriver','jdbc:oracle:oci7:');
The JDBC name and URL take different forms for different databases, as shown in the examples in the following table.
| Database | JDBC Driver and Database URL Examples |
|---|---|
IBM® Informix® | JDBC driver: com.informix.jdbc.IfxDriver Database URL: jdbc:informix-sqli://161.144.202.206:3000: |
MySQL® | JDBC driver: twz1.jdbc.mysql.jdbcMysqlDriver Database URL: jdbc:z1MySQL://natasha:3306/metrics JDBC driver: com.mysql.jdbc.Driver Database URL: jdbc:mysql://devmetrics.mrkps.com/testing |
Oracle oci7 drivers | JDBC driver: oracle.jdbc.driver.OracleDriver Database URL: jdbc:oracle:oci7:@rex |
Oracle oci8 drivers | JDBC driver: oracle.jdbc.driver.OracleDriver Database URL: jdbc:oracle:oci8:@111.222.333.44:1521: Database URL: jdbc:oracle:oci8:@frug |
Oracle thin drivers | JDBC driver: oracle.jdbc.driver.OracleDriver Database URL: jdbc:oracle:thin:@144.212.123.24:1822: |
Oracle 10 connections with JDBC (thin drivers) | JDBC driver: oracle.jdbc.driver.OracleDriver In this example, the target machine on which the database server resides is 144.212.123.24 and the port number is 1822. |
PostgreSQL | JDBC driver: org.postgresql.Driver Database URL: jdbc:postgresql://masd/MOSE |
PostgreSQL with SSL connection | JDBC driver: org.postgresql.Driver Database URL: jdbc:postgresql:servername:dbname:ssl= |
Microsoft® SQL Server™ | JDBC driver: com.microsoft.jdbc.sqlserver.SQLServerDriver Database URL: jdbc:sqlserver://localhost:port;database=databasename |
Sybase SQL Server® and Sybase® SQL Anywhere® | JDBC driver: com.sybase.jdbc.SybDriver Database URL: jdbc:sybase:Tds:yourhostname:yourportnumber/ |
close, dmd, exec, fastinsert, get, getdatasources, isconnection, isreadonly, logintimeout, ping, supports, update ,Using Visual Query Builder
![]() | cursor.fetch | database.fetch | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |