Hello i am currently building a programm that register users to mysql database. Everything works fine on localhost but when i try to connect to external database it gives me an error such as this below.

I have granted all privileges to the user in the database i am trying to acess and also i have the driver installed. Any ideas??
My code:
private void createEventListenerDBProperties() {
dbSubmitBtn.addActionListener((ActionEvent e) -> {
if (dbDriverChooser.getSelectedItem().equals("com.mysql.jdbc.Driver")) {
driver = (String) dbDriverChooser.getSelectedItem();
port = dbPortField.getText();
host = "jdbc:mysql://" + hostField.getText() + ":" + port + "/";
db = dbnameField.getText();
dbuser = dbUsernameField.getText();
dbpassword = new String(dbPasswordField.getPassword());
}
}
});
}
private Connection instanciateDB() {
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(host + db, dbuser, dbpassword);
System.out.println("Connection Established");
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Connection not Established");
JOptionPane.showMessageDialog(Project2.this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
return con;
}
username@localhostmeaning mysql will not allow the user to connect from remote addresses, so ensure you've setupusername@*. That being said, the error you show is more indicative of tcp ip issues, so trytelnet [your host] 3306at command prompt (dos or *nix will work) and make sure you can connect. Note that the model you're trying to do (local app connects to remote mysql) is not generally advisable, those types of connections are not encrypted and should generally occur over a trusted network only (e.g. a LAN).