Cannot create PoolableConnectionFactory (Communications link failure

数据库连接失败

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseProductName(VendorDatabaseIdProvider.java:77)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseName(VendorDatabaseIdProvider.java:62)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseId(VendorDatabaseIdProvider.java:50)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:395)

检查你的数据源配置即Resource中的:url,username,password
url   这个一般是"jdbc:mysql://localhost:3306/test",一定要注意3306  ,是mysql的默认端口

url=jdbc:mysql://localhost:3306/test中的localhost,也不是随便配置的,要看你的数据库中的from host
也可以写成url=jdbc:mysql://127.0.0.1:3306/test
还有就是 username要写正确,否则错误提示: java.sql.SQLException: Access denied for user ‘’ @'localhost' (using password: YES) 

还有要检测mysql服务开启了没有。

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




你可能感兴趣的:(【BUG总结】)