I have this problem with my swing application: "java.lang.classnotfoundexception com.mysql.jdbc.driver with swing". When I created a connection I added mysql connector lib file and I made a test. It was successful. Now I am connected and I can see every table in my database. The problem is when I want to create a simple select query.
public class DatabaseManager {
public static Connection getMySqlConnection() throws Exception {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/Sample";
String username = "root";
String password = "123";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
}
java -classpath pathToJARFile/myJARFile.jar;.; packageName.ClassNameWithMainMethod
Now press Enter. No need to specify .class after Class Name. – nIcE cOw 15 hours ago