jdbcmysql-connector

No suitable driver found using mysql-connector-java 8.0.33


I have a java program that used to work and then it stopped working.

The error that I am getting is

java.sql.SQLException: No suitable driver found for jdbc:mysql://feldspar:3306/sndm

I looked into what changed, and one thing that changed was the version of mysql-connector-java. In the last version that worked, the pom.xml contained

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.16</version>
  <optional>true</optional>
</dependency>

and in the version that did NOT work the pom.xml contained

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.33</version>
  <optional>true</optional>
</dependency>

(Note that the dependency is optional because I use maven-shade-plugin to build different JARs for different databases.)

So I tried reverting to 8.0.16, and it started working again.

So then I tested with different versions of the driver, and I found that with 8.0.30 it worked, but with 8.0.31, 8.0.32 and 8.0.33 it does not work.

My code does NOT call Class.forName() or DriverManager.registerDriver(). My understanding is that these methods are no longer required, and that JDBC should find the correct driver based on the URI.

Is there a known issue with mysql-connector-java version 8.0.33?

p.s.

I am using Java 11

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

Solution

  • The official JDBC driver for MySQL is mysql-connector-j, not mysql-connector-java.

    The latest version of mysql-connector-j works.

    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
      <version>9.2.0</version>
      <optional>true</optional>
    </dependency>