I am getting this Error - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver. I am using Notepad++ to code and command prompt to execute this program. No IDE.
I have installed latest version of MySQL,Java SE,Java Connector. I have set CLASSPATH variable correctly to mysql-connector-java-8.0.20.jar file. You can check CLASSPATH in below image [1]: https://i.stack.imgur.com/9XgQp.jpg
My Code is also Correct I have placed my code and output below. //Database program for MYSQL with java. Simple connection in notepad.
import java.sql.*;
public class Db01
{
public static void main(String args[])
{
try {
System.out.println("Start of program");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from studenttable");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception E)
{
System.out.println(E);
System.out.println("Program end with cought exception");
}
}
}
and Heres my output. Start of program
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Program end with cought exception
I tried most Documentations and forums but could not find answer please help me about this.