2016-05-12 102 views
-1

我的代碼:如何將託管的mysql數據庫連接到jsp?

String connectionurl="jdbc:mysql://parthramiz.esy.es/u804261533_impac"; 
Class.forName("com.mysql.jdbc.Driver"); 
String user="abc"; 
String passwd="****"; 
Connection con=DriverManager.getConnection(connectionurl,user,passwd); 

錯誤發生:

CommunicationsException:通信鏈路故障發送到服務器的最後的分組是0毫秒前。

使用哪個連接字符串?

+0

你應該提供你的代碼,你在哪裏得到這個錯誤。 –

+0

String connectionurl =「jdbc:mysql://parthramiz.esy.es/u804261533_impac」; \t \t Class.forName(「com.mysql.jdbc.Driver」); \t \t String user =「abc」; \t \t String passwd =「****」; \t \t \t \t Connection con = DriverManager.getConnection(connectionurl,user,passwd); –

+0

@ParthModi始終更新您的問題。無需在評論中編寫代碼。 –

回答

0

這種錯誤可能會發生少數事情。

因此,首先要檢查的是您的localhost MySQL正在運行的位置。請通過輸入\s進行檢查。

接下來要確保端口號是一樣的。

如果仍然無法使其工作,那麼它可能是權限問題。授權grant all on *.*由「password」標識,然後運行flush特權,然後用localhost替換127.0.0.1並嘗試重新連接。

檢查這個SO post