I have searched far and wide everywhere, but none of the answers to this issue have helped me.

My problem: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

I have it added as an external JAR. After that didn't work, I converted my file to Maven and added the dependency for it, that still didn't help. I've tried everything people have suggested in the narrowest corners of the internet, yet to no avail.

I need some assistance.


I get that it might be required of me to rename it to com.mysql.jdbc.Driver, but it doesn't work with that name either. I renamed it cause that's the seeming path to it.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.sql.*" import="com.mysql.*" %>
<!DOCTYPE html>
<meta charset="ISO-8859-1">
<title>Add a new company</title>
<link href="bootstrap.css" type="text/css" rel="stylesheet">
    <h1>New Company</h1>
    <form method="post" action="CreateNewCompany">
                <td><input type="text" name="fullName"></td>
                <td><input type="text" name="email"></td>
                    <select class="form-control">
                        <option value="-1">Select an address</option>

                            String Query = "select * from addresses";
                            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company","root","1234");
                            Statement statement = conn.createStatement();
                            ResultSet resSet = statement.executeQuery(Query);
                            <option value="<%=resSet.getInt("addressId")%>"><%=resSet.getString("street")%></option>
                        catch(Exception ex){
                            out.println("Error: " + ex.getMessage());
                <td>List of Employees</td>
                <td><input type="text" name="employees"></td>
        <input type="submit" value="Submit" name="submit"> <input
            type="button" value="Back" name="return">

2 Answers

vicky9988 On

Here is one example to load the driver and get the connection object. check the below points


    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;

     public class ExampleLoadingDriver {
                public static void main(String[] args) {
                    try {
                        // The newInstance() call is a work around for some
                        // broken Java implementations

                    } catch (Exception ex) {
                        // handle the error

do not import com.mysql.jdbc.*

for getting the connection object

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;

    Connection conn = null;
            try {
                conn =
                   DriverManager.getConnection("jdbc:mysql://localhost/exampledb?" +
            } catch (SQLException ex) {
                // handle any errors            

2) check jar is added in your classpath.

3) Also, try to build your project manually.

Community On

It turns out that I had to download an older version of the connector and that made it work. Thank you all for your time and help!