Tuesday, November 3, 2009

Troubleshooting Matlab and MySQL

Matlab's got a half-decent database toolbox, but it's usually a huge pain to get working at first.

You can see some other blogs here or here for the code but one thing that hasn't been pointed out clearly enough is how bad the error reporting is.

Take this, for example:

driver = 'com.mysql.jdbc.Driver';
driver = which('mysql-connector-java-5.0.8-bin.jar');
javaaddpath(driver);
host = 'loclhost';
port = 3306;
dbname = 'MyTestDb';
user = 'tester';
password = 'god'; %The Plague wouldn't like this...
url = ['jdbc:mysql://' host ':' num2str(port) '/' dbname];
db = database(dbname, user, password, driver, url)


Looks ok, but returns the error JDBC Driver Error: com.mysql.jdbc.Driver. Driver Not Found/Loaded. Which of course would send any normal person off on a wild goose chase -- Is the jar file corrupted? Is there supposed to be a 64-bit version? Maybe I should use the fixed java class path instead of the dynamic one?

But it's just a stupid typo: 'loclhost' instead of 'localhost'. Most stupid connection string mistakes you can make (user names, port numbers, etc) will result in the same missing driver error.

1 comment:

  1. try this.....
    http://matlab-adiarray.blogspot.co.id/2016/02/matlab-lihat-dan-simpan-data-di-mysql.html

    ReplyDelete