If the server hosts you and wants to "open it to the internet" if you are going to have to open ports, regarding what you have put in your code, I am not entirely sure if it is correct. To check it, instead of using your public ip (assuming that this server that you host is local, if not, use the public ip), use localhost:
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost:puerto/prueba","user", "password");
If it does not work like this, the problem is in its public ip, or it is not configured correctly, or the port is not open (although I repeat that if the server is in localhost it is not necessary to open it to be able to test it locally). / p>
On the documentation of the jdbc library, the syntax they use to connect is different from the one you have, so you could also try the following code:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/prueba?" +
"user=user&password=pass");
Substituting the values of user
and pass
for yours.