I have a problem with my code using Apache Netbeans 11.1
In this version of Netbeans I can't add a new library in my project so I set the mysql-connector-java-8.0.17 going to right-click on my project->properties->compile->manage java platform-> and set in source section the jar file.
I've already set new database connection by service window and it works, but when I execute the code of another project it can't connect to the mysql database.
This is my code:
import java.sql.*;
class esempio {
private String url = "jdbc:mysql://localhost:3306/student";
private String driver = "com.mysql.jdbc.Driver";
private String userName = "root";
private String password = "password";
private Connection con = null;
public void getConnection() {
try {
Class.forName(driver);
if(con == null) {
con = DriverManager.getConnection(url,userName,password);
}
System.out.print("Connection estd");
}
catch (Exception e) {
System.out.print("Error : " + e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] args) {
esempio nuovo=new esempio();
nuovo.getConnection();
}//endmain
}
but the output says:
Error : com.mysql.jdbc.Driverjava.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:315) at esempio.getConnection(esempio.java:28) at esempio.main(esempio.java:44)