mybatis connection error Cannot create PoolableConnectionFactory (Access denied for user 'root '@'local


 

 

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))
### The error may exist in com/sample/mappers/EmployeeMapper.xml
### The error may involve com.sample.dao.EmployeeDao.listall
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))

 

 

 

notice: the user is 'root ' not 'root'

這個問題大致就是需要檢查你的數據源配置即Resource中的:url,username,password

url這個一般是"jdbc:mysql://localhost:3306/test",一定要注意3306,這個是你數據庫連接用的端口,可以把它改成別的,但是如果你用的tomcat容器,別把它寫成8080,這樣就會產生Cannot create PoolableConnectionFactory (Communications link failure問題,還有就是url=jdbc:mysql://localhost:3306/test中的localhost,也不是隨便配置的,要看你的數據庫中的from host

我當時實在MySql Workbench5.2 CE中的 Users and Privileges中,有個Server Access Management

User  From Host 你看From Host中有沒有localhost,如果有你就能寫成url=jdbc:mysql://localhost:3306/test,要是from host有127.0.0.1的話,也可以寫成url=jdbc:mysql://127.0.0.1:3306/test

還有就是 username=  這個一定要寫正確,我當時寫的是name= ,結果mysql找不到username,然后他自動把username設為"",以至於錯誤提示: java.sql.SQLException: Access denied for user ‘’ @'localhost' (using password: YES) 你看到@前面是兩個單引號了嗎,那就是我沒輸入username而導致默認的默認username,其實這個錯誤也可以用設置權限改,但是那是mysql內容,就不說了。

總結起來就是:url端口要寫對,不能寫其他程序被占用的,127.0.01還是localhost要看數據庫里面有哪個,還要就是把對的驅動放入項目中的WEB-INF/lib里,這里提一下不用再放到tomcat的lib中。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM