我試圖連接到遠程服務器(我的學校服務器訪問數據庫),但我沒有任何運氣我不斷收到這個連接到遠程MySQL服務器引發錯誤
SQL Exception:
State : 08S01
Message: Communications link failure
Last packet sent to the server was 0 ms ago.
Error : 0
下面是一個代碼我發現在Java中,只是複製,看看我可以連接..
public void test()
{
try
{
// Load the database driver
Class.forName("com.mysql.jdbc.Driver") ;
// Get a connection to the database
Connection conn = DriverManager.getConnection("jdbc:mysql://my.db.url.edu;databaseName=marco;user=USERNAME;password=PASSWORD") ;
// Print all warnings
for(SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning())
{
System.out.println("SQL Warning:") ;
System.out.println("State : " + warn.getSQLState() ) ;
System.out.println("Message: " + warn.getMessage() ) ;
System.out.println("Error : " + warn.getErrorCode()) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the query
ResultSet rs = stmt.executeQuery("SELECT * FROM Test") ;
// Loop through the result set
while(rs.next())
System.out.println(rs.getString(1)) ;
// Close the result set, statement and the connection
rs.close() ;
stmt.close() ;
conn.close() ;
}
catch(SQLException se)
{
System.out.println("SQL Exception:") ;
// Loop through the SQL Exceptions
while(se != null)
{
System.out.println("State : " + se.getSQLState() ) ;
System.out.println("Message: " + se.getMessage() ) ;
System.out.println("Error : " + se.getErrorCode()) ;
se = se.getNextException() ;
}
}
catch(Exception e)
{
System.out.println(e) ;
}
}
}
只是爲了補充的信息,我使用Vista。可能是什麼問題?
問候
服務器可能被配置爲不接受遠程連接 – 2012-02-07 06:52:51
希望這是您的學校不允許互聯網上的所有內容進入數據庫。 – 2012-02-07 07:02:44
它不是我改變了那部分:) - 哦,實際上我們不需要連接到該數據庫..但沒有運氣..也許這是他們需要檢查的東西 – user710502 2012-02-07 07:03:40