我正在使用eclipse上的動態web應用程序,並試圖訪問遠程MySQL數據庫。我確信所有的信息都是正確的。但我似乎無法連接到它。這裏是我的getConnection方法:使用JDBC連接到遠程MySQL服務器問題
public static Connection getConnection() throws SQLException {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://50.56.81.42:3306/GUEST_BOOK";
String user = "username";
String password = "password";
conn = DriverManager.getConnection(url, user, password);
System.out.println("CONNECTED");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
return conn;
}
我想看看有什麼錯誤,而是因爲這是一個Web應用程序,我看不到任何地方的System.out.println,所以它是一種對我來說很難用這個進行調試。有關如何調試的任何建議?
''密碼「;'缺少'''' – triclosan
順便說一句,在Web應用程序中,您可以監視服務器錯誤日誌中的錯誤 – triclosan
如果您部署到集成在Eclipse中的服務器,您應該能夠在Eclipse的控制檯選項卡中看到它,否則,如果你正在導出一個WAR並手動將其部署到外部服務器上,那麼是的,你只需要讀取它的日誌。 – BalusC