Search code examples
javamysqldatabasedatabase-connectionclassnotfoundexception

I have problem solving ClassNotFoundExcepton for MYSQL connectivity, Cannot find Libraries folder Netbeans?


I am using MYSQL v8,Connector J8,Netbeans 12. Created very simple Maven java application to connect MySQL. I have added Connector8 to Classpath, I can run this program using CMD JDK works fine. Inside netbeans I used services tab added added driver; I also made connection to database there & I can see my database details in left panel. Still I keep getting

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/employeemanager?

Other solutions on stackoverflow inform me that I need to add .jar file to Library folder. I did not found library folder anywhere in project properties, theres no option to add jar in latest version. Please help me solving it.


Solution

  • I found the answer ! Using Netbeans 12 IDE, I was creating project using Maven. Libraries folder is not available in Maven Projects; Its available in 'Ant Projects'. For adding external Jar files in Maven projects you need to add Dependencies.

    Here I have given below steps to add MySQL Driver to Netbeans Maven Dependency

    1. Right click on Dependency folder click add dependancy
    2. Write details as ArtifactID : mysql-connector-java, GroupId : mysql,
    3. Check your Driver version and type in version box. eg 8.0.20
    4. Click on 'Add' button to add this dependency

    (Optional : if error occurs in adding/detecting corrrect Jar)

    1. Now you can see your driver automatically added in left, but caution mark.
    2. Right click driver and select 'Manual install artifact'
    3. Provide path to your .jar driver file. Done!