I think you're close.
It looks like you're using possibly Eclipse or STS in terms of your IDE. It's hard to tell from your snippets...but see if this attached screen with more info helps.
I assume your connection try-catch block is inside of a method like main, or some other method within the class. When you run the java class, are you running from inside Eclipse or from the command line? If from the command line, make sure you reference the classpath properly with the -cp argument (see the example). If you're on Windows, you'll need to reference both the MySQL jar file AND the build directory where your application's classes are. Make sure you use the right separator (: for Windows, ; for Linux and OSX).
This silly little application does most of what I could see from your snippet...and if it loads the driver successfully, and connects to MySQL, it prints out the following message.
"Connection is read-only: false"
[Example] https://i.stack.imgur.com/TRfT0.png