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

 

 

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))java

 

 

 

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

这个问题大体就是须要检查你的数据源配置即Resource中的:url,username,passwordspring

url这个通常是"jdbc:mysql://localhost:3306/test",必定要注意3306,这个是你数据库链接用的端口,能够把它改为别的,可是若是你用的tomcat容器,别把它写成8080,这样就会产生Cannot create PoolableConnectionFactory (Communications link failure问题,还有就是url=jdbc:mysql://localhost:3306/test中的localhost,也不是随便配置的,要看你的数据库中的from hostsql

我当时实在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/testapache

还有就是 username=  这个必定要写正确,我当时写的是name= ,结果mysql找不到username,而后他自动把username设为"",以致于错误提示: java.sql.SQLException: Access denied for user ‘’ @'localhost' (using password: YES) 你看到@前面是两个单引号了吗,那就是我没输入username而致使默认的默认username,其实这个错误也能够用设置权限改,可是那是mysql内容,就不说了。tomcat

总结起来就是:url端口要写对,不能写其余程序被占用的,127.0.01仍是localhost要看数据库里面有哪一个,还要就是把对的驱动放入项目中的WEB-INF/lib里,这里提一下不用再放到tomcat的lib中。mybatis

相关文章
相关标签/搜索