【发布时间】:2014-04-11 19:46:39
【问题描述】:
我正在尝试将 Apache DBCP 连接池技术与 Spring 结合使用,而我的数据库是 MySQL。我的 Apache DBCP 配置代码是:
@Bean(destroyMethod = "close") // destroyMethod attribute is used to close the bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("db.driver"));
dataSource.setUrl(environment.getRequiredProperty("db.url"));
dataSource.setUsername(environment.getRequiredProperty("db.username"));
dataSource.setPassword(environment.getRequiredProperty("db.password"));
dataSource.setInitialSize(5);
dataSource.setMaxTotal(5);
return dataSource;
}
但是当我尝试运行程序时,它会抛出异常:
java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))
为了解决这个异常,我已经google了它,并找到了这个答案:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
以 root 用户身份登录。但不幸的是,这不起作用,仍然会发生异常。所以我该怎么做?
我还尝试创建新用户并将所有权限授予新用户,但我仍然面临同样的异常。
【问题讨论】:
标签: java mysql exception jdbc apache-commons-dbcp