Java数据库连接池Druid报错com.alibaba.druid.pool.DruidDataSource error
druid
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
项目地址:https://gitcode.com/gh_mirrors/druid/druid
免费下载资源
·
直接上报错信息:
五月 11, 2021 11:12:41 上午 com.alibaba.druid.pool.DruidDataSource error
严重: testWhileIdle is true, validationQuery not set
五月 11, 2021 11:12:42 上午 com.alibaba.druid.pool.DruidDataSource error
严重: init datasource error
java.sql.SQLException: Access denied for user 'Annie'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:618)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:915)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:911)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98)
at cn.annie.dataSource.druid.DruidDemo1.main(DruidDemo1.java:28)
五月 11, 2021 11:12:42 上午 com.alibaba.druid.pool.DruidDataSource error
严重: dataSource init error
java.sql.SQLException: Access denied for user '86151'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:618)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:915)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:911)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98)
at cn.annie.dataSource.druid.DruidDemo1.main(DruidDemo1.java:28)
五月 11, 2021 11:12:42 上午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
Exception in thread "main" java.sql.SQLException: Access denied for user '86151'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:833)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:618)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:915)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:911)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98)
at cn.annie.dataSource.druid.DruidDemo1.main(DruidDemo1.java:28)
源文件的代码还是贴一下:
package cn.annie.jdbcTemplate;
import cn.annie.dataSource.utils.JDBCUtils;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* JdbcTemplate入门
*/
public class JdbcTemplateDemo1 {
public static void main(String[] args) {
// 1. 导入jar包
// 2. 创建JDBCTemplate对象。依赖于数据源DataSource
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
// 3. 调用JdbcTemplate的方法来完成CRUD的操作
String sql = "UPDATE account SET balance = ? where id = ?";
int count = jdbcTemplate.update(sql, 5000, 3);
System.out.println(count);
}
}
再来看我导入的包的版本信息:
commons-logging-1.2.jar
druid-1.0.9.jar
mchange-commons-java-0.2.19.jar
mysql-connector-java-8.0.24.jar
spring-beans-5.3.6.jar
spring-core-5.3.6.jar
spring-jdbc-5.3.6.jar
spring-tx-5.3.6.jar
再来看看我的配置文件druid.properties
# druid.properties文件的配置
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/db3
user=root
password=123456
# 初始化连接数量
initialSize=5
# 最大连接数
maxActive=10
# 最大超时时间
maxWait=3000
接下来我就开始了我无止境的百度操作,有人说是代理问题,有人说是配置文件问题,有人说是导入包的问题。
看了代理,没问题,看了配置文件没问题,起码没有写错的信息和单词,接着我把重心放在了包的版本上,改了无数个版本,不能说基本没什么用,只能说完全无用!!!
直到我百度到了一个这样的一篇文章,我发现了一个问题,于是再次去检查配置文件的参数,抱着死马当活马医的态度,我把user改成了username,啪,问题解决了,没报错真舒服。
忠告:好好看配置文件参数可以节约很多时间!
GitHub 加速计划 / druid / druid
27.83 K
8.56 K
下载
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
最近提交(Master分支:3 个月前 )
f060c270 - 8 天前
1613a765
* Improve gaussdb ddl parser
* fix temp table 10 天前
更多推荐
已为社区贡献1条内容
所有评论(0)