Connect MATLAB 7.0 and MYSQL

I want to connect MATLAB to MYSQL.I don't know how to do this. Help in MATLAB, he talks about some drivers that confuse me. Can someone please call me please tell me the complete process. I'll be very grateful!!!

+4
source share
1 answer

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 
+5
source

Source: https://habr.com/ru/post/1285853/


All Articles