Dhaval Mistry Dhaval Mistry - 4 months ago 12
SQL Question

I want to connect my java web application with mysql database but getting error

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.");
}
}

Answer

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.");
    }
}