Java MySQL Connection Error

Answered

Hi All,

I have downloaded the latest version of IntelliJ IDE (2016.3.4) and trying to connect to MySQL (code obtained from: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-connect-drivermanager.html) but keep getting the below error when I run my program:

"C:\Program Files\Java\jdk1.8.0_121\bin\......
Exception in thread "main" java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)

 

I have seen this problem on many forums but I am still having no luck when following the suggestions. I have tried adding the mysql connector java 5.1.40 JAR file to the project library and even global library but the error remains.

Does anyone have any suggestions??

Thanks,

Alex

0
2 comments

It looks like your run/debug configuration specifies a class that is not available. Either your project main class has a different name or it's not compiled. Check that Build step is enabled in the Run/Debug configuration. Does Build | Make produce the Main.class file in the output directory of the project?

Share the project if you still can't figure out what's wrong.

0
Avatar
Permanently deleted user

Hi Serge, I have created a new project and it seems to work now for some reason. I tried backtracking to see what went wrong for the last couple of hours but cant identify the problem. Thank you for the reply.

Alex.

0

Please sign in to leave a comment.