Home > Programming > Connect MATLAB with MySQL database

Connect MATLAB with MySQL database


Here is the code to connect MATLAB with MySql.

%database url
url = ‘jdbc:mysql://localhost:3306/’;
%test is a database, root is a user, admin is a password,
%com.mysql.jdbc.Driver is a driver name which was included into the folder
%and accordingly written the [matlabroot]/toolbox/local/classpath.txt
%$matlabroot/java/jar/mysql-connector-java-5.0.8-bin.jar
conn = database(‘test’, ‘root’, ‘admin’, ‘com.mysql.jdbc.Driver’, url);

curs = exec(conn,’SELECT * FROM emp’);
curs = fetch(curs);
curs.data

For the above program to work, you need to have Mysql Driver and you need to specify the path in the matlab path file. Once the above settings are made you can use mysql database from matlab.

How to set and what to set I’ve mentioned in the above program as comments. I hope this helps you.

Advertisements
  1. No comments yet.
  1. March 31, 2011 at 5:17 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: