MySQL连接:主机' x.y.z.z'不被允许

时间:2014-04-03 06:03:28

标签: mysql connection

我试图从客户端计算机(192.168.1.102)连接运行XAMPP 1.8.3(MySQL 5.6.16 GPL)的MySQL服务器(192.168.1.108),但是我收到此错误:

  

SQL Exception : null,来自服务器的消息:Host '192.168.1.108'是   不允许连接到这个MySQL服务器。

这是连接代码:

public Connection connect(String host) {
    try {                   
       String driver=textDriver.getText();
       // String host=textServer.getText();
       String db=textDatabase.getText();
       String user=textUser.getText();
       String pwd=txtPass.getText();       

       URL = "jdbc:mysql://"+ host +"/"+ db +"?user=" + user +"&password="+ pwd;

       Class.forName(driver);
       cn = DriverManager.getConnection(URL);
       connected=true;      

       JOptionPane.showMessageDialog(this, "Connection : " + cn.getCatalog(),
                                     "Database Connection",  
                                     JOptionPane.INFORMATION_MESSAGE);
       return cn;
    }
    catch (SQLException e){
       JOptionPane.showMessageDialog(this, "Not Connected : " + e);   
       return null;
    }
} 

这是主要代码(来电者):

public static void main(String[] args) {
    // 127.0.0.1
    String host = "localhost"; 
    try {
        String client = JOptionPane.showInputDialog(null, "Is this client(y/n)", "y");
        if (client .equals("y") || client.equals("Y")) {
            // Client must connect to the server(192.168.1.102)                
            host = "192.168.1.102";    
        }            

        Conn = dialog.connect(host);
        if (dialog.connected == true)   {                        
            dialog.setVisible(false);
            dialog.dispose();    
        }
    } catch (Exception e) {
        e.printStackTrace();
    }                                

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

请有人帮助我吗...

0 个答案:

没有答案