0
ClassNotFoundException in JDBC program
I am writing a simple program in Java using to demonstrate insertion of data in MySQL table using JDBC. But the program is generating ClassNotFoundException while registering driver. import java.sql.*; public class test { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e) { System.out.println("ClassNotFoundException: "+e.getMessage()); } } } I have added the driver JAR file in the same directory. To compile the program: javac -cp . test.java To execute the program: java -cp . test O/p: ClassNotFoundException: com.mysql.jdbc.Driver
5 Réponses
+ 2
Shashank Shekhar
You have to put jdbc jar file in the lib folder of JDK
+ 2
You most likely haven't added the jar to the classpath. Usually, a projects jar files are placed within a directory within the projects root named lib.
https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
https://javarevisited.blogspot.com/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html?m=1
+ 1
Or right click on the project, go to build path, click add external jars, select your mysql-connector jar file and give apply.
0
I am not using any IDE but I have put the jar file in the projects root directory. Then also this is happening.
0
I Am AJ !
I have put the jar file in lib folder of jdk then also this is happening.