2013-07-31 50 views
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連接數據庫連接,但它給了我一個錯誤:無法使用自己的數據庫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. 

我想我的這是第一次,因爲我是全新的虛擬主機,所以請提前幫助我!

+0

你可以在該特定主機上ping端口3306嗎? – Kayaman

+0

沒問題,它只是一個樣本分貝,我只需要知道如何連接它>? – user2496503

+1

檢查是否有防火牆可能會阻止端口上的連接。 –

回答

0

其相同或者您的本地或服務器上的

Class.forName("com.mysql.jdbc.Driver"); 
Connection connection = DriverManager.getConnection("jdbc:mysql://DomainName OR IP:3306/databasename", "username", "password"); 
+0

我想連接服務器 – user2496503

0

在000webhost.com上遠程MySQL連接是安全性和服務器性能的原因禁用。 如果您升級您的賬戶,MySQL連接將被啓用。