I have a java program which takes its information from MySQL it works fine when I use localhost to connect to it but whenever i put ipaddress in it it does not work. My connection code and exception are as follows.
package connection;
import java.net.InetAddress;
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author rpsal
*/
public class DBConnection {
public static Connection connect()//working on local host
{
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://"+getIpAddress()+"/ChatMaster";
conn = DriverManager.getConnection(url, "root", "");
} catch (Exception e) {
System.out.println("Exception in connect" + e);
}
return conn;
}
public static String getIpAddress() throws Exception {
InetAddress inetAddress = InetAddress.getLocalHost();
return inetAddress.getHostAddress();
}
}
When i use String url = "jdbc:mysql:///ChatMaster";
it works fine.
The exception i am getting is as follows.
Exception in connectjava.sql.SQLException: null, message from server: "Host 'Rp-Salh' is not allowed to connect to this MySQL server"