创建数据库连接池的时候,三个包mysql-connector-java-jar,commons-dbcp-1.4jar,commons-pool-1.5.5jar都导进去了,
文本文件也写了,
username=root;
password=lxn123
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
initialSize=10
maxActive=50
minIdle=5
maxWait=5000
但是还是出现了异常:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root;'@'localhost' (using password: YES))
运行代码如下:
@Test
public void testDBCPWithDataSourceFactlory() throws Exception{
Properties properties=new Properties();
InputStream in=
TestJDBC.class.getClassLoader().getResourceAsStream("dbcp.properties");
properties.load(in);
BasicDataSource dataSource=(BasicDataSource) BasicDataSourceFactory.createDataSource(properties);
System.out.println(dataSource.getConnection());
BasicDataSource basicDataSource=(BasicDataSource) dataSource;
System.out.println(basicDataSource.getMaxWait());
}
没看到Access denied这个错么?
密码错误?被拒绝了。
username=root;
password=lxn123
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/test
initialSize=10
maxActive=50
minIdle=5
maxWait=5000
http://www.cnblogs.com/gogly/p/3293328.html 希望能帮到你
我看出来了,是文件里面的username=root;处多了一个;号。谢啦
密码错了