0
我想連接到我的網站的MySQL數據庫,並且我對PHP沒有任何知識,因此我決定使用JDBC。我跟着一些視頻教程(非JDBC),我用他們的步驟。我跳過了MAMP步驟,因爲我沒有將服務器託管在我的PC上。它在本地託管,因爲它將成爲一個更大的網站。Android JDBC連接問題
所以我在我的登錄活動中輸入此代碼(第一個屏幕上看到):
Connection connection = null;
Statement statement = null;
String username = "username";
String password = "password";
String dbURL = "jdbc:mysql://216.26.176.52:3306/lifesizefoto";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(dbURL, username, password);
statement = connection.createStatement();
System.out.println("Connected.");
} catch (ClassNotFoundException error) {
System.out.println("Cannot connect");
} catch (SQLException error) {
System.out.println("Error: " + error.getMessage());
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (connection != null) { try {connection.close();} catch (SQLException ignore) {} }
if (statement != null) { try {statement.close();} catch (SQLException ignore) {} }
}
我已經嘗試了許多變化對被.getConnection()語句,但我不能弄明白。我也聯繫了網站主持人,他爲我的IP取下了所有的防火牆,甚至爲應用開闢了一個特殊的端口。
當我運行我的應用程序,我得到這個錯誤:
01-09 18:59:32.769: I/System.out(14178): Error: Communications link failure
01-09 18:59:32.769: I/System.out(14178): The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我希望得到任何幫助。先進的謝謝!
我打算首先做PHP,但這個版本只是測試版,我不知道如何在PHP中編寫代碼,所以我將學習下一個版本。 – user1513687
如果我連接到主機的SSL VPN,是否會將我置於其本地主機上?可能是 – user1513687
,但您需要檢查託管服務提供商的具體情況。 – GreyBeardedGeek