I am trying jdbc connection with mysql but getting SQLException.
My code is:–
public void createConn() throws MysqlException {
try {
String url ="jdbc:mysql://172.168.1.73:3306/mysql";
Connection con =DriverManager.getConnection(url,"root", "");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
}
i am getting following exception…
java.sql.SQLException: Access denied for user ‘root’@’192.168.1.187’
(using password: NO)
I am trying to connect to 172.168.1.73 but it is trying to coonect to 192.168.1.187…
root user doesnt have any password.
Please tell me how can i solve this issue.
Check whether root user can access the machine with IP 192.168.1.187
It is not trying to connect to 192.168.1.187.
‘root’@’192.168.1.187’ in the exception means a user with user name “root” in the machine with IP ‘192.168.1.187’ trying to access the database server. Therefore 192.168.1.187 is the client IP.
Database servers restricts the access based on user and the IP of the machine user use to connect. Therefore if you want to connect to the database server from a IP ‘192.168.1.187’, you should grant permission to access the user to access from that specific IP.
Check MySQL GRANT for more details.