Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database connection error #3

Closed
Philiphorst opened this issue Dec 12, 2014 · 4 comments
Closed

database connection error #3

Philiphorst opened this issue Dec 12, 2014 · 4 comments

Comments

@Philiphorst
Copy link
Contributor

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)
@Philiphorst
Copy link
Contributor Author

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

@Philiphorst
Copy link
Contributor Author

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

@benfulcher
Copy link
Owner

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)

@benfulcher
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants