'java.lang.classnotfoundexception:com.MYSQL.jdbc Driver in netbeans
i did project in netbeans 7.3.1 version and converted as jar if i run the jar from the dist folder means its work properly. if i copy and paste in desktop and run means it shows java.lang.classnotfoundexception:com.mysql.jdbc driver message will show. i could not find exactly. why it shows like that and what is the solution for it. please help me. am new to this netbeans... but added the mysql connector jar file in project. but it shows that error. please help me here is my code
package aam;
import java.sql.*;
import javax.swing.*;
public class Connect {
Connection con=null;
public static Connection ConnectDB(){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tnpcb","root","");
return con;
}
catch(ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
Solution 1:[1]
- Right click on Libraries > Click on Add Library.
- Scroll down to find MySQL JDBC driver.
- Press Shift + F11. (Clean and Build)
- Run
Solution 2:[2]
Setting the classpath :
- Download the JDBC MySQL Driver : https://dev.mysql.com/downloads/connector/j/
- Copy file in subfolder of project (ex: libs) (not 'src')
- Project->Properties->Libraries->Add Jar/Folder->Select file
And packaging dependent librairies with relative path in 'dist' :
- Project->Build->Packaging->Check "Copy Dependent Librairies"
- "Clean and Build"
Solution 3:[3]
- Right click in libraries
- Add Jar/Folder
- Add your mysql-connector-java-5.1.13-bin.jar
- right click in you project; click on "Clean and Build";
- After that go to the netbeans project folder;
- It creats a new folder called:"Dist" In this folder will have a file ProjectName.Jar (Does an executable of your application);
- In netbeans when you created the Jar a line appears in output and that you can copy and run in cmd.
If there is any error will appear and the Stacktrace code. And then we can better analyze the situation.
Solution 4:[4]
1/ Click libraries http://prntscr.com/pio7pr
2/ Add libraries : http://prntscr.com/pio80y
3/ Scroll down to find MySQL JDBC driver :http://prntscr.com/pio8e0
Solution 5:[5]
Include the dependent mysql-connector.jar in the classpath while running your application
Solution 6:[6]
If you are using MySQL 8.0, then use this driver name: "com.mysql.cj.jdbc.Driver". First of all download the libraries from the MySQL website then include them into your project. It will work smoothly.
Solution 7:[7]
I was working on Linux and encountered same error even after adding the jar and safely connecting from Services > Database window.
If you have obtained the jar and are getting same error after testing the Connection from Services > Database Window and it reports back connection success most likely you have not added the Jar in your libaries.
Go to Windows > Project > MyExampleProject > Libraries
Then Right Click > Add JAR/Folder
Add you sql-connector.jar
Now your jar is part of the libraries, now run your connection script again.
Solution 8:[8]
I'had this problem, and i found a solution that worked for me, if you have a maven project you have to follow this steps in order to add a dependency:
1 - right click on the the "dependecies" foleder.
2 - click "add dependency"
3 - write this inside the window that is gonna open:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Fhamtaom |
Solution 3 | rpirez |
Solution 4 | CertainPerformance |
Solution 5 | SparkOn |
Solution 6 | naeem1098 |
Solution 7 | MosesK |
Solution 8 | Mario Pascolat |