This is the wrong forum, moving to java.
There's not enough information in this error. It should provide you with a stack trace and an error line, otherwise you need to expand your catch output to show more information.
If I had to guess, you are loading a driver via a Class.forName or implicitly letting connection attempt to do so. This would indicate that you do not have the package for the driver available in the classpath during runtime which is why it still compiles properly. This can be configured in your IDE and included in a part of the manifest (if using a jar), or you can add it during the call with
-classpath path/to/package to the java command.