且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

诊断MATLAB My​​SQL JDBC驱动程序错误(Windows)

更新时间:2022-12-02 14:32:54

我已通过将MATLAB-R2017a与mysql-connector-java-8.0.11.jar结合使用来确认您的错误消息.

此页面描述Connector/J 8.0(包括mysql-connector-java-8.0.11.jar)仅支持JRE1.8.x.但是MATLAB R2017a使用JRE 1.7,因此R2017a不支持mysql-connector-java-8.0.11.jar.

为您提供三种选择.

  1. 使用Connector/J 5.1

    Connector/J 5.1支持JRE 1.7,因此它可与MATLAB R2017a一起使用,并且还支持MySQL Server 8.0.您可以从此处下载Connector/J 5.1.

  2. 将MATLAB更新到R2017b或R2018a

    从R2017b开始,MATLAB使用JRE 1.8,因此它可与Connector/J 8.0一起使用,包括您已经拥有的mysql-connector-java-8.0.11.jar.

  3. 在MATLAB中更改Java版本 我不会推荐这种方法,但是您可以将MATLAB的Java版本从1.7更改为1.8,它将与mysql-connector-java-8.0.11.jar一起使用.有关详细信息,请参见此页面.

Attempts, from MATLAB R2017a Windows-7, to connect to a database fail.

conn = database(dbsource,username,password,'Vendor','MySQL', 'Server','mysql8.db4free.net','portnumber',3306)

Error message: Unable to find JDBC driver

The JDBC driver was:

  1. Is there enough information here to diagnose the root cause of the error message?
  2. What is the root cause and corrective action?
  3. Why does MATLAB indicate the JDBC driver file is not on the java classpath? Remedy?

Responses to requests for additional diagnostic information will be added to the original posting.

Attempts to try these JDBC drivers were unsuccessful by individually testing each of these files in javaclass path:

  1. C:\drivers\mysql-connector-java-6.0.6\mysql-connector-java-6.0.6-bin.jar
  2. C:\drivers\mysql-connector-java-8.0.11\mysql-connector-java-8.0.11.jar

JDBC Driver 'Installation' of these comprises

  1. Unzipping the .jar driver to the target director
  2. Ensuring C:\Path\driver.jar is in MATLAB's javaclasspath
  3. Verifying that javaclasspath return C:\Path\driver.jar
  4. Verifying that C:\Path\driver.jar (returned in Step 3) at MATLAB prompt

    >> dir('C:\drivers\mysql-connector-java-6.0.6\mysql-connector-java-6.0.6-bin.jar')

Attempt to configure MATLAB's database explorer app returned the message:

 JDBC driver file was not found on MATLAB java classpath

Java version:

I have confirmed your error message by using mysql-connector-java-8.0.11.jar with MATLAB R2017a.

This page describes that Connector/J 8.0 (including mysql-connector-java-8.0.11.jar) supports only JRE 1.8.x. But MATLAB R2017a uses JRE 1.7, so mysql-connector-java-8.0.11.jar is not supported in R2017a.

There are three options for you.

  1. Use Connector/J 5.1

    Connector/J 5.1 supports JRE 1.7, so it works with MATLAB R2017a and also it supports MySQL Server 8.0. You can download Connector/J 5.1 from here.

  2. Update MATLAB to R2017b or R2018a

    From R2017b, MATLAB uses JRE 1.8, so it works with Connector/J 8.0, including mysql-connector-java-8.0.11.jar which you already have.

  3. Change Java version in MATLAB I will not recommend this approach, but you can change Java version of MATLAB from 1.7 to 1.8 and it would work with mysql-connector-java-8.0.11.jar. For detail, please see this page.