2014-10-29 73 views
0

我嘗試使用數據庫連接的Java應用程序時遇到了以上消息。.com.mysql.jdbc.exception.jbbc4.communicationexception..communication鏈接失敗

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. 

這裏我會在我的java應用程序中提到一些java代碼;我用來連接數據庫。

JDBC驅動程序名稱和數據庫URL

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 
static final String DB_URL = "jdbc:mysql://localhost/SORTS"; 

用戶名和密碼

static final String USER = "root"; 
static final String PASS = null; 

註冊JDBC驅動程序

Class.forName("com.mysql.jdbc.Driver"); 

// 「連接到所選數據庫...」

conn = DriverManager.getConnection(DB_URL, USER, PASS); 

我覺得這些MySQL服務器的信息也可能是有用

current database:sorts 
current user:[email protected] 
Connection:localhost via TCP/IP 
TCP port:3307 

回答

0

在URL中,你應該添加3307使用的端口號,(這是不是一個非標準...):

static final String DB_URL = "jdbc:mysql://localhost:3307/SORTS"; 

希望它有幫助。

0

你確定你的數據庫正在運行嗎?檢查並確保您的數據庫服務器已啓動並正在運行。另外,考慮到tacou_st aswer