我不斷收到當我試圖連接到我的MySQL數據庫這個錯誤連接到MySQL數據庫:不能在servlet的
exception
javax.servlet.ServletException: JDBC Problem:
root cause
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.
root cause
java.net.ConnectException: Connection timed out: connect
這裏的一些代碼:
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection
("jdbc:mysql://mysql11.000webhost.com/database_name","user_name","password");
stmt = con.createStatement();
rs = stmt.executeQuery("INSERT into emailadresses('email') values ('"+email+"')");
} catch (ClassNotFoundException ex) {
Logger.getLogger(EmailServlet.class.getName()).log(Level.SEVERE, null, ex);
}catch(SQLException e){
throw new ServletException("JDBC Problem: ", e);
}
編輯:我在我的圖書館
EDIT使用mysql-connector-java的jar文件:發現問題 我一直在尋找,我主持我的數據庫網站上的答案,並發現這一點:
JDBC/ODBC is not supported here
是S *中正...
你能夠從jvm運行的同一臺機器手動連接嗎? – lynks
其中一個問題可能是因爲您沒有指定端口。它應該看起來像'jdbc:mysql://mysql11.000webhost.com:3306/database_name' –