【问题标题】:connection of MATLAB 7.0 and MYSQLMATLAB 7.0 与 MYSQL 的连接
【发布时间】:2009-06-06 19:08:58
【问题描述】:

我想将 MATLAB 与 MYSQL 连接。我不知道该过程。在 MATLAB 帮助中,它提到了一些让我很困惑的驱动程序。有人可以指导我吗!请告诉我完整的过程。我将非常感谢! !!

【问题讨论】:

    标签: mysql matlab


    【解决方案1】:

    我使用 JDBC 从 MATLAB 连接到 mySQL 数据库。无缝运行。

    • 首先从这里下载适用于 mySQL 的 JDBC 驱动程序: http://www.mysql.com/downloads/connector/j/
    • 将 mysql-connector-java-x.x.xx-bin.jar(最新版本)文件从存档解压到一个文件夹中
    • 在脚本的开头添加此 jar 文件的路径,然后您可以连接到数据库等等。

    以下是连接和查询公共人类基因组数据库的示例:

    %# add path to the JAR file you just installed to Java dynamic classpath
    javaaddpath('h:\Documents\MATLAB\myJavaClasses\mysql-connector-java-5.1.12-bin.jar')
    %# connection parameteres
    host = 'genome-mysql.cse.ucsc.edu';
    user = 'genome';
    password = '';
    dbName = 'hg18'; 
    %# JDBC parameters
    jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
    jdbcDriver = 'com.mysql.jdbc.Driver';
    
    %# Create the database connection object
    conn = database(dbName, user , password, jdbcDriver, jdbcString);
    
    gene = 'NF1';
    if isconnection(conn) % check to make sure that we successfully connected
        qry = sprintf('SELECT geneName, chrom, txStart, txEnd FROM refFlat WHERE geneName=''%s''',gene);
        rs = fetch(exec(conn, qry));
        rsdata = get(rs, 'Data');
    end
    

    【讨论】:

      猜你喜欢
      • 2011-06-15
      • 2017-03-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 2013-11-15
      • 2014-06-23
      • 2013-10-03
      相关资源
      最近更新 更多