1

Driver Not Foundjava.lang.ClassNotFoundException: com.mysql.jdbc.driver

I want to make connection between my java web application and mysql database through XAMP. I also have added external jar file which is mysql-connector-java-6.0.2.jar but still i am getting this error.

I have done this code.

public static void main(String[] args) 
{
    try {
        Class.forName("com.mysql.jdbc.driver");
        System.out.println("Driver has been found..");
    } catch (ClassNotFoundException ex) {
        System.out.println("Driver Not Found"+ex);
    }

    String url="jdbc:mysql://localhost/hms";
    String user="root";
    String password="";

    Connection con=null;

    try {
        con=DriverManager.getConnection(url, user, password);
        System.out.println("Driver is successfully loaded.");
    } catch (SQLException ex) {
        System.out.println("Something is not good.");
    }
}
Mureinik
  • 277,661
  • 50
  • 283
  • 320
Dhaval Mistry
  • 363
  • 1
  • 8
  • 15
  • Possible duplicate of [Connect Java to a MySQL database](http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database) – Mark Rotteveel Jul 30 '16 at 10:41

2 Answers2

3

Class names in Java are case-sensitive. You need to capitalize the "D" in "driver":

Class.forName("com.mysql.jdbc.Driver");
// Here ----------------------^
Mureinik
  • 277,661
  • 50
  • 283
  • 320
2

You should write this because because java is Case-Sensitive

public static void main(String[] args) 
{
    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Driver has been found..");
    } catch (ClassNotFoundException ex) {
        System.out.println("Driver Not Found"+ex);
    }

    String url="jdbc:mysql://localhost/hms";
    String user="root";
    String password="";

    Connection con=null;

    try {
        con=DriverManager.getConnection(url, user, password);
        System.out.println("Driver is successfully loaded.");
    } catch (SQLException ex) {
        System.out.println("Something is not good.");
    }
}
Jahid Mahmud
  • 1,112
  • 1
  • 12
  • 30