I wrote a program to connect to a database using jdbc with type 4 connectivity. The program compiles just fine but gives an exception of java.lang.ClassNotFoundException : com.mysql.jdbc.Driver. I have extracted all the folders in the folder in which my java file is and even placed all the jar files and database in the same folder. The database contains two records with ID 1 and 2. What could be the problem?
import java.sql.*;
class TestJDBC {
public static void main(String aa[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Student_Details", "root","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select ID, studentname from Details where ID=1");
while(rs.next()) {
System.out.print(rs.getString("ID"));
System.out.print("\t");
System.out.println(rs.getString("StudentName"));
}
}
catch(Exception e) {
System.out.println(e);
}
}
}