我正在使用mysql與我的數據庫建立連接。代碼工作正常,但如果我輸入了錯誤的用戶名/密碼/主機/數據庫,我可以得到一個日誌消息,該部分是錯誤的?下面是代碼:Java和MySQL可以有調試日誌?
private void connectDatabase()
{
try {
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/"
+ database + "?autoReconnect=true", username, password);
System.out.println("[MySQL] The connection to MySQL is made!");
} catch (SQLException e) {
System.out.println("[MySQL] The connection to MySQL couldn't be made! reason: "
+ e.getMessage());
}
}
例:我輸入了錯誤的密碼,我得到這個錯誤日誌:
[MySQL] The connection to MySQL couldn't be made! reason: Wrong password.
這可能嗎?
你可以嘗試,並檢查 –
我想嘗試,但這個想法是我不知道從哪裏開始。 –
你的代碼很好,除非你得到的消息會更詳細。 –