错误:java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
原因:连接的用户名和密码错误(多打了空格)
网上找了有三种原因:
1、用户名和密码不匹配,或者是在连接池里多打了空格之类的
2、可能是用户的权限不够,给他添加权限
3、编码的问题
我很奇怪,明明一样的项目,一个报错一个没报错,我一个一个字符比对,十分钟过去了。
一点毛病没发现。灵机一动,去网上找在线对比工具
一看才发现多了个空格。 先给自己小脑袋瓜来一拳,涨涨记性
错误详细:
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@5c36a328)
LogAbandoned: true
RemoveAbandoned: true
RemoveAbandonedTimeout: 180
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘root’@‘localhost’ (using password: YES))
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at com.szearth.data.ConnectDB.GetConnection(ConnectDB.java:71)
at com.szearth.daoImpl.WxRankDaoImpl.queryRanks(WxRankDaoImpl.java:113)
at com.szearth.servlet.RankInit.doPost(RankInit.java:41)
at com.szearth.servlet.RankInit.doGet(RankInit.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.szearth.filter.EncodeFilter.doFilter(EncodeFilter.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol A b s t r a c t C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 585 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . J I o E n d p o i n t AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint AbstractConnectionHandler.process(AbstractProtocol.java:585)atorg.apache.tomcat.util.net.JIoEndpointSocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor W o r k e r . r u n ( T h r e a d P o o l E x e c u t o r . j a v a : 615 ) a t j a v a . l a n g . T h r e a d . r u n ( T h r e a d . j a v a : 744 ) C a u s e d b y : j a v a . s q l . S Q L E x c e p t i o n : A c c e s s d e n i e d f o r u s e r ′ r o o t ′ @ ′ l o c a l h o s t ′ ( u s i n g p a s s w o r d : Y E S ) a t c o m . m y s q l . j d b c . S Q L E r r o r . c r e a t e S Q L E x c e p t i o n ( S Q L E r r o r . j a v a : 1073 ) a t c o m . m y s q l . j d b c . M y s q l I O . c h e c k E r r o r P a c k e t ( M y s q l I O . j a v a : 3603 ) a t c o m . m y s q l . j d b c . M y s q l I O . c h e c k E r r o r P a c k e t ( M y s q l I O . j a v a : 3535 ) a t c o m . m y s q l . j d b c . M y s q l I O . c h e c k E r r o r P a c k e t ( M y s q l I O . j a v a : 934 ) a t c o m . m y s q l . j d b c . M y s q l I O . s e c u r e A u t h 411 ( M y s q l I O . j a v a : 4104 ) a t c o m . m y s q l . j d b c . M y s q l I O . d o H a n d s h a k e ( M y s q l I O . j a v a : 1299 ) a t c o m . m y s q l . j d b c . C o n n e c t i o n I m p l . c o r e C o n n e c t ( C o n n e c t i o n I m p l . j a v a : 2338 ) a t c o m . m y s q l . j d b c . C o n n e c t i o n I m p l . c o n n e c t O n e T r y O n l y ( C o n n e c t i o n I m p l . j a v a : 2371 ) a t c o m . m y s q l . j d b c . C o n n e c t i o n I m p l . c r e a t e N e w I O ( C o n n e c t i o n I m p l . j a v a : 2163 ) a t c o m . m y s q l . j d b c . C o n n e c t i o n I m p l . < i n i t > ( C o n n e c t i o n I m p l . j a v a : 794 ) a t c o m . m y s q l . j d b c . J D B C 4 C o n n e c t i o n . < i n i t > ( J D B C 4 C o n n e c t i o n . j a v a : 47 ) a t s u n . r e f l e c t . N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e 0 ( N a t i v e M e t h o d ) a t s u n . r e f l e c t . N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e ( N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . j a v a : 57 ) a t s u n . r e f l e c t . D e l e g a t i n g C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e ( D e l e g a t i n g C o n s t r u c t o r A c c e s s o r I m p l . j a v a : 45 ) a t j a v a . l a n g . r e f l e c t . C o n s t r u c t o r . n e w I n s t a n c e ( C o n s t r u c t o r . j a v a : 526 ) a t c o m . m y s q l . j d b c . U t i l . h a n d l e N e w I n s t a n c e ( U t i l . j a v a : 407 ) a t c o m . m y s q l . j d b c . C o n n e c t i o n I m p l . g e t I n s t a n c e ( C o n n e c t i o n I m p l . j a v a : 378 ) a t c o m . m y s q l . j d b c . N o n R e g i s t e r i n g D r i v e r . c o n n e c t ( N o n R e g i s t e r i n g D r i v e r . j a v a : 305 ) a t o r g . a p a c h e . c o m m o n s . d b c p . D r i v e r C o n n e c t i o n F a c t o r y . c r e a t e C o n n e c t i o n ( D r i v e r C o n n e c t i o n F a c t o r y . j a v a : 38 ) a t o r g . a p a c h e . c o m m o n s . d b c p . P o o l a b l e C o n n e c t i o n F a c t o r y . m a k e O b j e c t ( P o o l a b l e C o n n e c t i o n F a c t o r y . j a v a : 294 ) a t o r g . a p a c h e . c o m m o n s . d b c p . B a s i c D a t a S o u r c e . v a l i d a t e C o n n e c t i o n F a c t o r y ( B a s i c D a t a S o u r c e . j a v a : 1247 ) a t o r g . a p a c h e . c o m m o n s . d b c p . B a s i c D a t a S o u r c e . c r e a t e D a t a S o u r c e ( B a s i c D a t a S o u r c e . j a v a : 1221 ) . . . 25 m o r e 三 月 13 , 20205 : 05 : 06 下 午 o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d W r a p p e r V a l v e i n v o k e 严 重 : S e r v l e t . s e r v i c e ( ) f o r s e r v l e t [ R a n k I n i t ] i n c o n t e x t w i t h p a t h [ / P i n g p o n g ] t h r e w e x c e p t i o n j a v a . l a n g . R u n t i m e E x c e p t i o n : o r g . a p a c h e . c o m m o n s . d b c p . S Q L N e s t e d E x c e p t i o n : C a n n o t c r e a t e P o o l a b l e C o n n e c t i o n F a c t o r y ( A c c e s s d e n i e d f o r u s e r ′ r o o t ′ @ ′ l o c a l h o s t ′ ( u s i n g p a s s w o r d : Y E S ) ) a t c o m . s z e a r t h . d a t a . C o n n e c t D B . G e t C o n n e c t i o n ( C o n n e c t D B . j a v a : 74 ) a t c o m . s z e a r t h . d a o I m p l . W x R a n k D a o I m p l . q u e r y R a n k s ( W x R a n k D a o I m p l . j a v a : 113 ) a t c o m . s z e a r t h . s e r v l e t . R a n k I n i t . d o P o s t ( R a n k I n i t . j a v a : 41 ) a t c o m . s z e a r t h . s e r v l e t . R a n k I n i t . d o G e t ( R a n k I n i t . j a v a : 28 ) a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 621 ) a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 722 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 305 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 210 ) a t c o m . s z e a r t h . f i l t e r . E n c o d e F i l t e r . d o F i l t e r ( E n c o d e F i l t e r . j a v a : 37 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 243 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 210 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d W r a p p e r V a l v e . i n v o k e ( S t a n d a r d W r a p p e r V a l v e . j a v a : 222 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d C o n t e x t V a l v e . i n v o k e ( S t a n d a r d C o n t e x t V a l v e . j a v a : 123 ) a t o r g . a p a c h e . c a t a l i n a . a u t h e n t i c a t o r . A u t h e n t i c a t o r B a s e . i n v o k e ( A u t h e n t i c a t o r B a s e . j a v a : 472 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d H o s t V a l v e . i n v o k e ( S t a n d a r d H o s t V a l v e . j a v a : 168 ) a t o r g . a p a c h e . c a t a l i n a . v a l v e s . E r r o r R e p o r t V a l v e . i n v o k e ( E r r o r R e p o r t V a l v e . j a v a : 99 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d E n g i n e V a l v e . i n v o k e ( S t a n d a r d E n g i n e V a l v e . j a v a : 118 ) a t o r g . a p a c h e . c a t a l i n a . c o n n e c t o r . C o y o t e A d a p t e r . s e r v i c e ( C o y o t e A d a p t e r . j a v a : 407 ) a t o r g . a p a c h e . c o y o t e . h t t p 11. A b s t r a c t H t t p 11 P r o c e s s o r . p r o c e s s ( A b s t r a c t H t t p 11 P r o c e s s o r . j a v a : 1002 ) a t o r g . a p a c h e . c o y o t e . A b s t r a c t P r o t o c o l Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:934) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4104) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1299) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163) at com.mysql.jdbc.ConnectionImpl.
at org.apache.tomcat.util.net.JIoEndpoint S o c k e t P r o c e s s o r . r u n ( J I o E n d p o i n t . j a v a : 312 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . r u n W o r k e r ( T h r e a d P o o l E x e c u t o r . j a v a : 1145 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor SocketProcessor.run(JIoEndpoint.java:312)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘root’@‘localhost’ (using password: YES))
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at com.szearth.data.ConnectDB.GetConnection(ConnectDB.java:71)
… 23 more
Caused by: java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:934)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4104)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1299)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
… 25 more