ErrorOracle
java

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Error message

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

What broke

The application is trying to connect to a MySQL database but cannot find the necessary JDBC driver class. This typically happens when the driver is not included in the project's dependencies.

Why it broke

It broke because the Java runtime environment cannot locate the `com.mysql.jdbc.Driver` class, which is essential for establishing a connection to a MySQL database. This usually occurs when the MySQL Connector/J library is missing from the classpath.

How to fix

To fix this issue, you need to add the MySQL JDBC driver to your project's dependencies. If you're using Maven, you can add the dependency to your `pom.xml`. If you're not using a build tool, download the JAR file and include it in your classpath.

Code fix

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

Explained by ErrorOracle

Prevention tip

If you're not using a build tool, download the JAR file and include it in your classpath.

Was this helpful?

AI-generated explanation. Always verify fixes in your codebase.