Reputation: 2883
private DBHandler(String ServerIP, String userName, String password)
{
DB_USERNAME = userName;
DB_PASSWORD = password;
DB_CONNECTION_URL = "jdbc:mysql://"+ServerIP+"/Test";
connection = createConnetcion(DB_DRIVER, DB_CONNECTION_URL, DB_USERNAME, DB_PASSWORD);
System.out.println("Connection created");
}
when executing this code java sql exception occured."Host 'WS1A101.ushustech.com' is not allowed to connect to this MySQL server". Is any complaint for my code? what is exactly wrong here?
Upvotes: 0
Views: 664
Reputation: 669
Your need to set permission for your host in MySQL. In your case it should be something like
GRANT ALL PRIVILEGES on Test.* to 'user'@'WS1A101.ushustech.com' identified by 'password';
FLUSH PRIVILEGES;
Upvotes: 0
Reputation: 1336
put DB_CONNECTION_URL = "jdbc:mysql://ws1a101.ushustech.com/Test";
instead of DB_CONNECTION_URL = "jdbc:mysql://"+ServerIP+"/Test";
Upvotes: 0
Reputation: 360872
Unless your mysql account was created as username@name_of_machine_you_connect_from
or username@ip_of_machine_you_connect_from
, or uses a wildcard username@%
, you won't be allowed to connect. If it is using the hostname version, make sure that there's a reverse DNS mapping in place, so mysql can map the IP address it sees back to the hostname that's listed in the user table.
Upvotes: 0
Reputation: 1410
Nothing wrong with code, ask your DBA to give your machine permission to connect to that database
Upvotes: 0
Reputation: 2453
Have your DBA check that connections from your client machine are allowed to connect to the Database.
Upvotes: 2