I'm building up a Maven Java 1.8 project in which I've included the MySQL Connector as a dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
In my application I've a singleton that holds the MySQL connection so when the application starts, the MySQL connector is triggered but I got a ClassNotFoundException for the driver that I'm using: com.mysql.cj.jdbc.Driver.
The JDBC URL that I'm using is:
jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false
I'm using IntelliJ IDEA (2017.2) IDE.
I've checked in File -> Project Structure -> Libraries -> I see "Maven: mysql:mysql-connector-java:5.1.392" as a Library.
I've also checked under File -> Project Structure -> Artifacts -> and under myapp.war exploded -> WEB-INF -> lib -> Maven: mysql:mysql-connector-java:5.1.39 is present.
From View -> Tool Windows -> Database, I've succesfully made a MySQL connection dowloading the suggested driver (MySQL Connector 5.1.35).
How can I tell the application that it has to load the MySQL driver at runtime?
Thanks in advance
In the file browser, navigate to the JAR file of the JDBC driver, select it, and click OK. In the Class field, specify the value that you want to use for the driver . Click Apply.
To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.
Try upgrading your driver. Coz Mysql community has updated class name from com.mysql.jdbc.Driver
to com.mysql.cj.jdbc.Driver
Check out more on MySql Community
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
Or Download jar file direct from here :
mysql-connector-java-8.0.11.jar
List of MySql jar file
If you're facing this problem with Eclipse, I've been following many different solutions but the one that worked for me is this:
Right click your project folder and open up Properties.
From the right panel, select Java Build Path then go to Libraries tab.
Select Add External JARs to import the mysql driver.
From the right panel, select Deployment Assembly.
Select Add..., then select Java Build Path Entries and click Next.
You should see the sql driver on the list. Select it and click first.
And that's it! Try to run it again!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With