Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException

mysql数据库老连接不上,而我的Mysql Workbench能正常运行

九月12, 2018 8:46:22上午org.apache.catalina.core.StandardWrapperValve invoke 
严重: Servlet.service() for servlet [springmvc] in context with path [/DCC] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Client does not support authentication protocol requested by server; consider upgrading MySQL client)

The error may exist in file [F:\RCMS\RCMS-master\build\classes\dao\user\UserMapper.xml]

The error may involve dao.user.UserMapper.login

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Client does not support authentication protocol requested by server; consider upgrading MySQL client)] with root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source) 
at com.mysql.jdbc.Util.handleNewInstance(Util.java:353) 
at com.mysql.jdbc. Util.getInstance(Util.java:336) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:985) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2938) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:855) 
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3337 ) 
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1217) 
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1930) 
at com.mysql.jdbc.Connection.(Connection.java:716 ) 
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( Unknown Source) 
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:353) 
at com.mysql.jdbc.Connection.getInstance(Connection.java:295) 
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266 ) 
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) 
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) 
at org.apache.commons.dbcp.BasicDataSource. validateConnectionFactory(BasicDataSource.java:1556) 
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545) 
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection (DataSourceUtils.java:77) 
at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) 
at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:66) 
at org.apache. ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279) 
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:72) 
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java: 59)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) 
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137) 
at org.apache.ibatis.executor.CachingExecutor.query (CachingExecutor.java:96) 
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77) 
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108) 
at org. apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102) 
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method ) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354) 
at com.sun. proxy.$Proxy28.selectOne(Unknown Source) 
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159) 
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68) 
at org.apache .ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) 
at com.sun.proxy.$Proxy33.login(Unknown Source) 
at service.user.UserServiceImpl.login(UserServiceImpl.java:22) 
at sun.reflect. NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection (AopUtils.java:317) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework. aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.interceptor.ExposeInvocationInterceptor .invoke(ExposeInvocationInterceptor.java:91) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
at com. sun.proxy.$Proxy42.login(Unknown Source) 
at controller.LoginController.doLogin(LoginController.java:33) 
at controller.LoginController$$FastClassBySpringCGLIB$$1c890173.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) 
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700) 
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor .intercept(CglibAopProxy.java:633) 
at controller.LoginController$$EnhancerBySpringCGLIB$$c8132d32.doLogin() 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun. reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) 
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
at org.springframework.web.servlet .mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743) 
at org.springframework.web.servlet .mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672) 
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919) 
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851) 
at org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:953) 
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) 
at org.springframework.web. servlet.FrameworkServlet.service(FrameworkServlet.java:829) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
at org.apache.catalina.core.ApplicationFilterChain .internalDoFilter(ApplicationFilterChain.java:193) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 
at org. springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) 
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:96) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 
at org.apache. catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) 
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight .java:66) 
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) 
at org. apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org .apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

 

问题解决:使用的数据库是MySQL,驱动是6.0.3,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。

最后终于搞定了,在一个CSDN博客上找到了最后的解决方法,真是浪费了我接近一天的时间!

原作者链接:https://blog.csdn.net/oppo5630/article/details/52162783

你可能感兴趣的:(JavaWeb)