1
  try {
        String connectionURL = "jdbc:mysql://sql4.000webhost.com/a7291194_xxx";
        Connection connection = null; 
        Class.forName("com.mysql.jdbc.Driver").newInstance(); 
        connection = DriverManager.getConnection(connectionURL, "a7291194_xxx", "xxx");
        if(!connection.isClosed())
             System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");
        connection.close();
    }catch(Exception ex){
        System.out.println("Unable to connect to database"+ex);
    }   

使用以下连接器代码,我尝试连接 000webhost.com 上的数据库,但它给了我一个错误:

    CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. 
    The driver has not received any packets from the server.

我第一次尽力而为,因为我对虚拟主机完全陌生,所以请帮助我提前谢谢!

4

2 回答 2

0

在您的本地或服务器上都一样

Class.forName("com.mysql.jdbc.Driver");  
Connection connection = DriverManager.getConnection("jdbc:mysql://DomainName OR IP:3306/databasename", "username", "password");
于 2013-07-31T11:33:50.073 回答
0

出于安全和服务器性能的原因,在 000webhost.com 上,远程 MySQL 连接被禁用。如果您升级您的帐户,将启用 MySQL 连接。

于 2014-07-16T08:09:51.297 回答