`
deepfuture
  • 浏览: 4412284 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80130
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70350
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103591
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:286571
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15054
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:67786
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32292
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46075
社区版块
存档分类
最新评论

matlab-数据库连接

 
阅读更多

1、连接数据库

1)相关参数

help database
  Database Toolbox
  Version 3.7 (R2010a) 25-Jan-2010
 
   General functions:
 
   chkprops      - Database object properties.
   logintimeout  - Set or get time allowed to establish database connection.
   setdbprefs    - Set preferences for database actions for handling null values.
 
   Database Access functions:
 
   database/catalogs           - Get database catalog names.
   database/clearwarnings      - Clear warnings for database connection.
   database/close              - Close database connection.
   database/columns            - Get database table column names.
   database/commit             - Make database changes permanent.
   database/database           - Connect to database.
   database/exec               - Execute SQL statement and open cursor.
   database/fetch              - Import data into MATLAB using connection handle.
   database/get                - Get database property.
   database/insert             - Export MATLAB cell array data to database table.
   database/isconnection       - Detect if database connection is valid.
   database/isreadonly         - Detect if database connection is read-only.
   database/ping               - Get status information about database connection.
   database/rollback           - Undo database changes.
   database/runstoredprocedure - Stored procedures with input and output parameters.
   database/schemas            - Get database schema names.
   database/set                - Set properties for database connection.
   database/sql2native         - Convert JDBC SQL grammar into system's native SQL grammar.
   database/tables             - Get database table names.
   database/update             - Replace data in database table with data from MATLAB cell array.
 
   Database Cursor Access functions:
 
   cursor/attr         - Get attributes of columns in fetched data set.
   cursor/close        - Close cursor.
   cursor/cols         - Get number of columns in fetched data set.
   cursor/columnnames  - Get names of columns in fetched data set.
   cursor/fetch        - Import data into MATLAB.
   cursor/get          - Get property of cursor object.
   cursor/querytimeout - Get time allowed for a database SQL query to succeed.
   cursor/rows         - Get number of rows in fetched data set.
   cursor/set          - Set RowLimit for cursor fetch.
   cursor/width        - Get width of column in fetched data set.
 
   Database Toolbox Object functions:
 
   dbtbx/dbtbx      - Construct Database Toolbox object.
   dbtbx/display    - Database Toolbox object display method.
   /dbtbx/subsasgn   - Subscripted assignment for Database Toolbox object.
   dbtbx/subsref    - Subscripted reference for Database Toolbox object.
 
   Database Toolbox Database MetaData functions:
 
   dmd/bestrowid         - Get database table unique row identifier.
   dmd/columnprivileges  - Get database column privileges.
   dmd/columns           - Get database table column names.
   dmd/crossreference    - Get information about primary and foreign keys.
   dmd/dmd               - Construct database metadata object.
   dmd/exportedkeys      - Get information about exported foreign keys.
   dmd/get               - Get database metadata properties.
   dmd/importedkeys      - Get information about imported foreign keys.
   dmd/indexinfo         - Get indices and statistics for database table.
   dmd/primarykeys       - Get primary key information for database table or schema.
   dmd/procedurecolumns  - Get catalog's stored procedure parameters and result columns.
   dmd/procedures        - Get catalog's stored procedures.
   dmd/supports          - Detect if property is supported by database metadata.
   dmd/tableprivileges   - Get database table privileges.
   dmd/tables            - Get database table names.
   dmd/versioncolumns    - Get automatically updated table columns.
 
   Database Toolbox Driver functions:
 
   driver/driver     - Construct database driver object.
   driver/get        - Get database driver properties.
   driver/isdriver   - Detect if driver is a valid JDBC driver object.
   driver/isjdbc     - Detect if driver is JDBC-compliant.
   driver/isurl      - Detect if database URL is valid.
   driver/register   - Load database driver.
   driver/unregister - Unload database driver.
 
   Database Toolbox Drivermanager functions:
 
   drivermanager/drivermanager  - Construct database drivermanager object.
   drivermanager/get            - Get database drivermanager properties.
   drivermanager/set            - Set database drivermanager properties.
 
   Database Toolbox Resultset functions:
 
   resultset/clearwarnings  - Clear the warnings for the resultset.
   resultset/close          - Close resultset object.
   resultset/get            - Get resultset properties.
   resultset/isnullcolumn   - Detect if last record read in resultset was null.
   resultset/namecolumn     - Map resultset column name to resultset column index.
   resultset/resultset      - Construct resultset object.
 
   Database Toolbox Resultset MetaData functions:
 
   rsmd/rsmd  - Construct resultset metadata object.
   rsmd/get   - Get resultset metadata properties.
 
   Database Toolbox bulk insert examples:
 
   dbdemos/mssqlserverbulkinsert  - MS SQL Server bulk insert example.
   dbdemos/mysqlbulkinsert  - MySQL bulk insert example.
   dbdemos/oraclebulkinsert - Oracle bulk insert example.
 
   Visual Query Builder functions:
 
   vqb/confds              - Configure data source (UNIX only).
   vqb/getdatasources      - Return valid data sources on system.
   vqb/loginconnect        - Datasource connection.
   vqb/parsebinary         - Write binary object to disk.
   vqb/qbhelp              - Query Builder help string.
   vqb/querybuilder        - Start visual SQL query builder.
   vqb/showdata            - Display data in interactive window.
   vqb/showdatacallbacks   - Visual Query Builder data display callbacks.
   vqb/vqbdemo             - Visual Query Builder demonstrations.


database is both a directory and a function.

 DATABASE Connect to database.
    CONNECT = DATABASE(INSTANCE,USERNAME,PASSWORD,DRIVER,DATABASEURL)
    returns a database connection object. INSTANCE is the name of the
    database, USERNAME is the user name. PASSWORD is the password
    that permits access to the database. DRIVER is a JDBC driver name and
    DATABASEURL is the URL for the database. The latter arguments are
    optional but both must be used in conjunction with each other.
 
    Use LOGINTIMEOUT before DATABASE to set the maximum time for a
    connection attempt.
 
    Example:
 
    JDBC-ODBC connection:
 
    conn=database('oracle','scott','tiger')
 
    where:
 
    'oracle' is the ODBC datasource name for an ORACLE database.
    'scott'  is the user name.
    'tiger'  is the password.
 
 
    JDBC connection:
 
    conn=database('oracle','scott','tiger',
                 'oracle.jdbc.driver.OracleDriver','jdbc:oracle:oci7:')
 
    where:
 
    'oracle' is the database name.
    'scott'  is the user name.
    'tiger'  is the password.
    'oracle.jdbc.driver.OracleDriver' is the JDBC driver to be used
                                      to make the connection.
    'jdbc:oracle:oci7:' is the URL as defined by the Driver vendor
                        to establish a connection with the database.
   
    See also close.

 

 

JDBC的driver 例子 

IBM Informix

JDBC driver: com.informix.jdbc.IfxDriver

Database URL: jdbc:informix-sqli://161.144.202.206:3000:
INFORMIXSERVER=stars

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
Database URL: jdbc:oracle:thin: (do not specify the target name and port)

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=
true&sslfactory=org.postgresql.ssl.NonValidatingFactory& (the trailing & is required)

Microsoft SQL Server

JDBC driver: com.microsoft.jdbc.sqlserver.SQLServerDriver

Database URL: jdbc:microsoft:sqlserver://localhost:port;database=databasename

Note   For MS SQL Server 2005, the Driver and URL syntax has changed to:

JDBC driver: com.microsoft.sqlserver.jdbc.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/

 

 

JDBC连接数据库的参数:

 

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.

Note   The JDBC driver is sometimes referred to as the class that implements the Sun Java SQL driver for your database.

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.

Find the correct driver name

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'

 

2)连接mysql

a)如果是测试开发用,可以下载安装xampp

http://www.apachefriends.org/zh_cn/xampp-windows.html

b)安装JDBC驱动

http://dev.mysql.com/downloads/mirror.php?id=408558

安装mysql驱动程序包,详细步骤如下:
Step 1: 将mysql-connector-java-5.1.21-bin.jar文件拷贝到......MATLAB\R2011b\java\jar\toolbox

Step 2: 到......\MATLAB\R2009a\toolbox\local目录下,找到classpath.txt文件,打开,并添加用来加载mysql的jdbc驱动语句:
$matlabroot/java/jar/toolbox/mysql-connector-java-5.1.21-bin.jar

Step 3:重新打开MATLAB即可

c)编写代码连接

 myconn=database('test','root','','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/test')
 myconn =
 
       Instance: 'test'
       UserName: 'root'
         Driver: 'com.mysql.jdbc.Driver'
            URL: 'jdbc:mysql://localhost:3306/test'
    Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
        Message: []
         Handle: [1x1 com.mysql.jdbc.JDBC4Connection]
        TimeOut: 0
     AutoCommit: 'on'
           Type: 'Database Object'

>> ping(myconn)

ans =

       DatabaseProductName: 'MySQL'
    DatabaseProductVersion: '5.5.25a'
            JDBCDriverName: 'MySQL-AB JDBC Driver'
         JDBCDriverVersion: [1x60 char]
    MaxDatabaseConnections: 0
           CurrentUserName: 'root@localhost'
               DatabaseURL: 'jdbc:mysql://localhost:3306/test'
    AutoCommitTransactions: 'True'

设置连接超时时限
>> logintimeout('com.mysql.jdbc.Driver',10)

ans =

    10

>>

分享到:
评论

相关推荐

    matlab开发-数据库地窖射线

    MATLAB提供了多种数据库连接工具,如Database Toolbox,使得用户可以方便地连接到各种类型的数据库,如SQL Server、Oracle、MySQL等。使用这些工具,我们可以创建数据库连接,执行SQL语句,以及读取和写入数据。 在...

    matlab开发-数据库工具箱

    总的来说,MATLAB数据库工具箱结合Matlabadt库,为音频数据的分析和处理提供了一个强大且灵活的环境,使得研究人员和开发人员能够专注于他们的核心任务,而不必过多关注底层的数据库操作。无论是简单的数据检索还是...

    Matlab与PostgreSQL数据库的连接

    将 Matlab 与 PostgreSQL 数据库连接起来,可以实现数据的高效交互和分析。本文将详细介绍 Matlab 与 PostgreSQL 数据库的连接方法。 知识点:Matlab 的数据库连接 Matlab 提供了多种方式来连接数据库,其中包括...

    matlab开发-数据库中的大型数据处理案例研究

    这通常涉及数据库连接、查询和数据提取,是大型数据处理的关键步骤。 4. **README.m** 和 **README.pdf**:这些文件提供了关于项目的基本信息和使用指南。它们通常包含了如何运行代码、所需环境、依赖项以及可能的...

    matlab开发-访问数据库

    在进行MATLAB数据库开发时,理解基本的数据库连接和查询方法,以及如何利用自定义工具如`MYM.M`,将极大地提高你的工作效率。确保遵守许可证规定,并合理利用提供的辅助工具,将使你在MATLAB数据库编程中游刃有余。

    matlab与sql数据库连接

    matlab与sql数据库连接,实例说明,M文件

    Matlab与数据库连接.rar

    一、Matlab数据库连接概述 Matlab提供了一种灵活的接口,使得用户能够直接在Matlab环境中操作各种类型的数据库,包括关系型数据库如Oracle、MySQL、SQL Server,以及非关系型数据库如MongoDB等。通过内置的Database...

    matlab与数据库的连接

    综上所述,MATLAB与数据库的连接涉及到数据库技术的基础应用、MATLAB的数据处理能力、远程数据库连接的设置、编程环境的配置、数据获取方法、以及MATLAB Database工具箱的具体应用。通过对这些知识点的理解和应用,...

    基于MATLAB的数据库开发.pdf

    开发基于外部数据源的MATLAB数据库涉及的关键技术是ODBC(开放式数据库连接)。 ODBC作为数据库应用的接口,为不同的数据库管理系统提供了一个统一的数据库接口标准。它由三部分组成:API(应用程序接口)、驱动...

    Matlab与数据库连接.pdf

    标题中的“Matlab与数据库连接”指的是在MATLAB环境下如何与数据库进行交互,实现数据的导入和导出。MATLAB是一种强大的数值计算和数据分析工具,它提供了与多种类型数据库(如Access)连接的功能,以便于在MATLAB...

    matlab开发-A制冷数据库连接

    在MATLAB中进行数据库连接是开发过程中的一个重要环节,特别是在处理和分析大量数据时。"A制冷数据库连接"这个项目可能涉及到将MATLAB与特定的制冷行业相关的数据库系统相结合,以便进行数据查询、分析和存储操作。...

    基于MATLAB的数据库开发

    基于外部数据源的MATLAB数据库开发** 外部数据源通常指的是通过ODBC(Open Database Connectivity)接口连接的数据库。ODBC是一个标准的API,允许不同的DBMS之间进行通信。MATLAB通过ODBC-JDBC桥接器与数据库建立...

    matlab访问mysql数据库教程及代码

    其中,conn 是数据库连接对象,'select * from table1' 是要执行的 SQL 语句。 接下来,可以使用 fetch 函数来获取查询结果: curs = fetch(curs) 最后,可以使用 data 属性来获取查询结果: cur = curs.data ...

    MATLAB、数据库、GUI的构建代码

    这涉及到MATLAB的数据库连接函数,如`database`,以及相关的配置步骤,包括创建数据源(DSN)和设置连接参数。 2. SQL语言的运用:SQL(Structured Query Language)是用于管理和处理关系型数据库的标准语言。在...

    matlab开发-从映像创建数据库

    1. **连接数据库**:MATLAB支持多种数据库接口,如ODBC(开放数据库连接)和JDBC(Java数据库连接)。首先,脚本会使用`database`函数建立到数据库服务器的连接,定义数据库类型、服务器地址、用户名、密码等参数。 ...

    Matlab与数据库连接[收集].pdf

    MATLAB提供了与多种数据库连接的功能,包括ODBC(Open Database Connectivity)接口,使得数据交换变得更加方便。 首先,建立数据库是整个过程的基础。这里以Access数据库为例,你需要在Access中创建一个新的数据库...

    Matlab与数据库连接(20211029163901).pdf

    最后,`close`函数用于关闭游标和数据库连接,释放资源。 除了基本的连接和查询,MATLAB还支持更复杂的数据库操作,如插入、更新和删除数据,以及事务处理。例如,你可以使用`insert`, `update`, `delete`等SQL命令...

    matlab开发-ChangeSystemDSNToadifferencesAccess数据库

    2. **MATLAB代码实现**:在MATLAB中,你可以使用`database`函数创建一个数据库连接对象,该对象使用DSN作为参数。例如: ```matlab conn = database('DSN_NAME','USER_ID','PASSWORD'); ``` 其中,'DSN_NAME'是...

    matlab gui与数据库Access编程详解

    总的来说,MATLAB GUI与数据库Access的编程涉及数据库连接、SQL查询、GUI组件的回调函数、数据处理和用户交互等多个方面。通过熟练掌握这些技术,可以构建出高效、易用的数据管理应用。在实际项目中,应考虑性能优化...

Global site tag (gtag.js) - Google Analytics