java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)

原文链接 :http://blog.csdn.net/lindonglian/article/details/48001441

早上在做MyBatis+spring整合的时候爆了个奇葩的bug,

遇到这个问题换一个读取配置文件方法即可,测试成功!

之前用同一个MySQL都是可以的,现在password=YES !!

 

百度虽然很强大,找个解决方案还真不容易,应该很少人会出现同样的。。

既然问题出现在数据库连接上,那就应该找数据库连接相关的配置。

 

最后问题的解决在配置文件导入上,我这里是

<context:property-placeholder location="classpath:db.properties" /> 

有网友是这样导入的

  1.  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    
  2.     <property name="locations">    
  3.         <list>    
  4.             <value>classpath*:db.properties</value>    
  5.         </list>    
  6.     </property>    
  7. </bean>  
  1. rg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:   
  2. ### 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 'Administrator'@'localhost' (using password: YES))  
  3. ### The error may exist in sqlmap/User.xml  
  4. ### The error may involve test.findUserById  
  5. ### The error occurred while executing a query  
  6. ### 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 'Administrator'@'localhost' (using password: YES))  
  7.     at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)  
  8.     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)  
  9.     at $Proxy5.selectOne(Unknown Source)  
  10.     at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)  
  11.     at test.lindl.sm.dao.impl.UserDaoImpl.findUserById(UserDaoImpl.java:18)  
  12.     at test.lindl.sm.dao.impl.UserDaoImplTest.testFindUserById(UserDaoImplTest.java:24)  
  13.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  14.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  15.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  16.     at java.lang.reflect.Method.invoke(Method.java:597)  
  17.     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)  
  18.     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)  
  19.     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)  
  20.     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)  
  21.     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)  
  22.     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)  
  23.     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)  
  24.     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)  
  25.     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)  
  26.     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)  
  27.     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)  
  28.     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)  
  29.     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)  
  30.     at org.junit.runners.ParentRunner.run(ParentRunner.java:292)  
  31.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)  
  32.     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  
  33.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)  
  34.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  35.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  36.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  37. Caused by: org.apache.ibatis.exceptions.PersistenceException:   
  38. ### 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 'Administrator'@'localhost' (using password: YES))  
  39. ### The error may exist in sqlmap/User.xml  
  40. ### The error may involve test.findUserById  
  41. ### The error occurred while executing a query  
  42. ### 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 'Administrator'@'localhost' (using password: YES))  
  43.     at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)  
  44.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)  
  45.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)  
  46.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)  
  47.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
  48.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
  49.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
  50.     at java.lang.reflect.Method.invoke(Method.java:597)  
  51.     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)  
  52.     ... 28 more  
  53. Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'Administrator'@'localhost' (using password: YES))  
  54.     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)  
  55.     at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)  
  56.     at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)  
  57.     at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)  
  58.     at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:72)  
  59.     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)  
  60.     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)  
  61.     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)  
  62.     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)  
  63.     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)  
  64.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)  
  65.     ... 35 more  
  66. Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'Administrator'@'localhost' (using password: YES))  
  67.     at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)  
  68.     at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)  
  69.     at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)  
  70.     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)  
  71.     ... 45 more  
  72. Caused by: java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)  
  73.     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)  
  74.     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)  
  75.     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)  
  76.     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)  
  77.     at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)  
  78.     at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)  
  79.     at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)  
  80.     at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2535)  
  81.     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2320)  
  82.     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)  
  83.     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)  
  84.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
  85.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)  
  86.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)  
  87.     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)  
  88.     at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  
  89.     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)  
  90.     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)  
  91.     at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)  
  92.     at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)  
  93.     at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)  
  94.     at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)  
  95.     ... 48 more  
posted @ 2017-09-01 09:38  伍春晖  阅读(1954)  评论(1编辑  收藏  举报