benfulcher / hctsa

Highly comparative time-series analysis

Home Page:https://time-series-features.gitbook.io/hctsa-manual/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

database connection error

Philiphorst opened this issue · comments

mysql_dbopen.m throws error even after including the appropriate connector via

javaaddpath('/home/philip/work/CompEngineMatlab/Database/mysql-connector-java-5.1.34-bin.jar')
% -- Error -- 
Error using mysql_dbopen (line 24)
Error with java database connector: Java exception occurred:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)

There is a work-around using the database toolbox.

Another method is using a method suggested in http://stackoverflow.com/questions/24438359/connecting-matlab-and-mysql-with-the-jdbc-driver

My new and working (for me) mysql_dbconnect.m looks like this

function [dbconnection, errmsg] = mysql_dbopen(serverhost, dbname, uname, pword)

javaaddpath('/home/philip/work/CompEngineMatlab/Database/mysql-connector-java-5.1.34-bin.jar')

% Open database
errmsg = []; % error message

% Now try to connect    

try
    d = com.mysql.jdbc.Driver;
    dburl = sprintf('jdbc:mysql://%s/%s', serverhost, dbname);
    props = java.util.Properties;
    props.put('user',uname); props.put('password',pword);
    dbconnection = d.connect(dburl,props);
catch le
    fprintf(1,'Error connecting to the database ''%s'' at ''%s'':\n%s\n',dbname,serverhost,le.message);
    fprintf(1,['Perhaps an incorrect username (''%s'') and password (''%s'') combination?\n'], uname, pword);
    dbconnection = [];
    % Not really a Matlab 'error' -- just print the suspected problem to screen
end

And it works like a charm. I think the problem lies with the

java.lang.Class.forName('com.mysql.jdbc.Driver', true, cl)

method. But that is just gut feeling

The mysql_dbconnect.m seems to create a memory issue with java when running on multiple timeseries on my machine which results in a complete freeze of matlab.
java.lang.OutOfMemoryError: PermGen space

Running out of memory usually happens when you're trying to retrieve a huge set of time series/operations. Matlab needs to keep the whole retrieval in memory, and it has a hard limit on this. The java heap size can be increased in the Matlab preferences:
f5245bac-a00c-46f7-b346-bcd4b6824548
(A related problem is exceeding the max_allowed_packet, and can be adjusted by changing the number of chunks for SQL_add_chunked: cf. lines 364--378 in SQL_add)

This is now fixed -- mysql_dbopen uses the database toolbox if a license is available, otherwise reverts to the original implementation.