So you moved db from local machine to some provider's server.
And what about apache? I don't get it?
Have you moved your web app from local apache to remote provider's apache??
If you have then everything is on provider's side.
In provider's own network there are now 2 servers one is apache and other mysql.
If you connect to DB from some java class on that apache i cannot see problem, provider always set those 2 servers so they can communicate.
But if you connect from java class on apache that is on your own home PC
to remote provider's mysql DB that is totally different situation.
In this case you are in one part of network administrated from your ISP
that probably gives you some dynamic IP, and that mysql DB server is in
some intranet of that free web hosting company, but they have to protect it in some way,
so i don't know if that mysql has some static IP and is configured so someone from outside can reach it.
I don't know if this helped you,
but be sure you have to deal with this stuff sooner or later on every project
so take your time and we will help you solve it