无法连接到java中的mysql

时间:2012-12-15 18:40:29

标签: java mysql

我尝试使用MySQL连接到JAVA我使用相同的代码连接我的localhost中的数据库。现在我尝试在我的系统中使用它来更新远程数据库。这是我的代码:

import java.sql.*;
class mysqlConnect { 

public static void main (String[] args) { 
    try { 
        String url = "jdbc:mysql://dibyaranjan.net76.net/a3932573_product";
        Connection conn = DriverManager.getConnection(url,"a3932573_dibya","*****"); 
        Statement st = conn.createStatement(); 
        st.executeUpdate("INSERT INTO emp_oracle " + "VALUES (1001, 'Dibya', 'AAA')"); 
        conn.close(); 
    } catch (Exception e) { 
        System.err.println(e.getMessage()); 
    } 

}
} 

我收到此错误消息: null,来自服务器的消息:“主机'49 .204.14.98'不允许连接到此MySQL服务器”

ip是我的公共IP。

2 个答案:

答案 0 :(得分:1)

错误很明显。您无法从您的计算机连接到远程mysql服务器。 a3932573_dibya此用户无权从此IP连接。

在mysql中创建用户时,我们还可以指定此用户将连接的所有IP。如果您想允许所有IP,您应该将主机设为%

答案 1 :(得分:0)

您的主机在mysql.user表格中配置不正确。

打开PHPMyAdmin并在mysql.user表格中找到您的记录。 ALTER表格,而不是localhost127.0.0.1或任何其他IP,主机名反映您的实际IP(或%,如果您希望允许来自每个IP的连接。但请注意,大多数共享主机不允许这种配置。

更多参考:http://blog.wassupy.com/2011/02/host-is-not-allowed-to-connect-to-this.html