我無法連接到我的數據庫。我認爲這是一個我不瞭解的需要改變的地方。我在這裏有一些非常基本的代碼:MySQLNonTransientConnectionException:無法創建與數據庫服務器的連接。嘗試重新連接3次。放棄
public static void main(String[] args)
{
try
{
Connection con = DriverManager.getConnection("jdbc:mysql://IP:3306/TABLENAME?autoReconnect=true","USERNAME", "PASSWORD");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
顯然與登錄信息。它會導致這個錯誤:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: com.mysql.jdbc.exceptions.jdbc4.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.
Caused by: java.net.ConnectException: Connection refused
我已經通過大約10個不同的崗位看上去差不多的問題,並試圖解決他們仍然無法得到它的工作。
http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai –
@FastSnail我嘗試了所有的BalusC技巧,但仍然遇到同樣的問題。 –
也閱讀這篇文章http://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql –