1. 程式人生 > 實用技巧 >解決java.sql.SQLException: Access denied for user 'dzt'@'localhost' (using password: YES)

解決java.sql.SQLException: Access denied for user 'dzt'@'localhost' (using password: YES)

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
# Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: 
Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: 
Access denied
for user 'dzt'@'localhost' (using password: YES) 1 The error may exist in com/dkc/mapper/UserMapper.xml 2 The error may involve com.dkc.mapper.UserMapper.selectUserByUserName 3 The error occurred while executing a query 4 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException:
Access denied
for user 'dzt'@'localhost' (using password: YES)

根據錯誤提示,大概有這四部分需要檢查,

1.檢查對應的xml內容是否寫對,主要圖中三個箭頭標記的地方。

2.檢查第二部分就是mapper介面中對應的方法,一般這個不會出錯,出錯原因就是第一個原因

3.檢查第三部分就是在執行過程中出現問題,檢查對應的CRUD語句

4.檢查資料庫的賬號和密碼是否正確,如果已經確保自己的 賬戶和密碼正確,那麼可以在yml或者porperties檔案中賬戶和密碼加上雙引號(說明:具體原因也不知道,自己建立了一個新專案,根據原來的配置檔案可以訪問,但是在原來專案上配置檔案賬戶和密碼必須加雙引號)