Failed to load driver class com.mysql.jdbc.Driver

We Are Going To Discuss About Failed to load driver class com.mysql.jdbc.Driver. So lets Start this Java Article.

Failed to load driver class com.mysql.jdbc.Driver

  1. Failed to load driver class com.mysql.jdbc.Driver

    The answer is so embarrassing. I appended the driver line of application.properties with a semicolon …
    Obviously, it did't recognize that driver.

  2. Failed to load driver class com.mysql.jdbc.Driver

    The answer is so embarrassing. I appended the driver line of application.properties with a semicolon …
    Obviously, it did't recognize that driver.

Solution 1

In my case the next dependency was missing:

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
</dependency>

In case of using IntelliJ and if you inherit from a <parent>, you can view your effective pom.xml by right clicking anywhere inside your pom.xml, then:
enter image description here

and search for the mysql-connector-java artifact as mentioned.

Original Author IKo Of This Content

Solution 2

The answer is so embarrassing. I appended the driver line of application.properties with a semicolon …
Obviously, it did’t recognize that driver.

Original Author IKo Of This Content

Solution 3

just add mysql and jdbc dependencies like below

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>

Original Author Omid Rostami Of This Content

Solution 4

I had a problem where I was using Spring Boot 2.2.0.RELEASE and needed to connect to an old Mysql DB (5.1.73), which required me to downgrade to mysql-connector-java version 5.1.38

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.38</version>
    </dependency>

Since Spring boot was expecting a newer mysql-java-connector, which has been renamed to com.mysql.cj.jdbc.Driver, I also had to add the spring datasource driver-class-name setting in my spring boot db config.

So my spring boot config ended up like this:

spring:
  datasource:
   url: 'localhost'
   password: password
   username: user
   driver-class-name: com.mysql.jdbc.Driver

Original Author Andreas Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment