- 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.
Configure JDBC connection on Mojave
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
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
댓글 수: 0
답변 (1개)
  TARUN
 2025년 6월 11일
        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: 
Feel free to go through the documentation of methods used:  
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

