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.
我想我的這是第一次,因爲我是全新的虛擬主機,所以請提前幫助我!
你可以在該特定主機上ping端口3306嗎? – Kayaman
沒問題,它只是一個樣本分貝,我只需要知道如何連接它>? – user2496503
檢查是否有防火牆可能會阻止端口上的連接。 –