Configure JDBC connection on Mojave

9 views (last 30 days)
Gian23
Gian23 on 11 May 2019
Answered: TARUN on 11 Jun 2025 at 7:00
Hi, I'm new in the community but before to make my question I tried unsuccessfully to find the answer in a lot of topics.
I need to create a connection by code to a localhost mySQL database in OSX Mojave.
First of all I downloaded the Connector/J 8.0.16 Platform Independent driver called 'mysql-connector-java-8.0.16.jar' and I copied it in a subfolder of my rootfolder called Jconnector with the following code:
rootfolder = '/Users/User/Documents/MATLAB/MatlabResearch/RobustTS/';
addpath(rootfolder);
% jdbc
jdbcfolder = [rootfolder 'Jconnector/'];
jdbcjarfile = 'mysql-connector-java-8.0.16.jar';
% database
databasename = 'RAWDATA';
user = 'root';
password = 'password';
driver = 'com.mysql.cj.jdbc.Driver';
databaseurl = ['jdbc:mysql://localhost:3306/' databasename];
% table name(s)
table_indexed = 'mytable';
table = table_indexed;
% add jdbc driver info
javaaddpath([jdbcfolder jdbcjarfile]);
% connect to database
conn = database(databasename, user, password, driver, databaseurl);
And I get this error:
Warning: Invalid file or directory
'/Users/User/Documents/MATLAB/MatlabResearch/RobustTS/Jconnector/mysql-connector-java-8.0.16.jar'.
> In javaclasspath>local_validate_dynamic_path (line 271)
In javaclasspath>local_javapath (line 187)
In javaclasspath (line 124)
In javaaddpath (line 71)
And the message in the connection proprierties. 'No suitable driver found ...'
I can't understand if my procedure fails in the code of in some preliminary step (like managing of JAVACLASS).
Could someone help me? I would be very glad.
Thanks in advance,
Gian

Answers (1)

TARUN
TARUN on 11 Jun 2025 at 7:00
Hi @Gian23,
It looks like you're trying to connect MATLAB to a local MySQL database using the JDBC driver on macOS Mojave, but you're running into issues like "invalid file or directory" for the .jar and a "no suitable driver found" message.
This usually happens due to either the driver not being properly located or registered, or a misstep in the configuration. You can try the following steps to resolve the problem:
  • Make sure the path to the .jar file is correct, and the file exists at that location.
  • Use fullfile() instead of string concatenation when forming file paths, to avoid formatting issues especially on macOS.
  • Run javaclasspath('-dynamic') to verify that the JDBC .jar was successfully added to MATLAB’s Java classpath.
  • Double-check that the MySQL server is running and accessible at localhost:3306, and that login credentials and database name are correct.
Feel free to go through the documentation of methods used:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!