I am using JDBC to connect from MATLAB database to mySQL. It works smoothly.
- First download the JDBC driver for mySQL from here: http://www.mysql.com/downloads/connector/j/
- Unzip the mysql-connector-java-xxxx-bin.jar file (latest version) from the archive to the folder
- At the beginning of your script, add the path to this jar file, then you can connect to the database, etc.
Here is an example of connecting and querying the human human genome database:
%# 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
source share