The code compiles and runs fine. It looks like you don't have the correct file name in use, or that you're not running the javac properly if manually doing it from the command line.
Did you use an IDE for this, or did you just create a text file? Check the directory for this, and see what the extension is (it has to be .java).
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php