Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

java - MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection

I built an web application and deployed locally working perfect. I deployed it on a remote server and started getting the : exception

> javax.servlet.ServletException: could not execute query 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518) 
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421) 


>root cause 

>org.hibernate.exception.JDBCConnectionException: could not execute query 
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74) 
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
org.hibernate.loader.Loader.doList(Loader.java:2223) 
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) 
org.hibernate.loader.Loader.list(Loader.java:2099) 
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94) 
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
data.dao.UserDAO.findByUsername(UserDAO.java:42) 
action.registration.LoginAction.execute(LoginAction.java:24) 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
java.lang.reflect.Method.invoke(Method.java:597) 
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:399) 
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:262) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:224) 
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:213) 
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150) 
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48) 
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:161) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.PrepareInterceptor.intercept(PrepareInterceptor.java:115) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) 
com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) 
com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216) 
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50) 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:507) 
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421) 

>root cause 

>com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: 


** BEGIN NESTED EXCEPTION ** 
    >com.mysql.jdbc.exceptions.jdbc4.CommunicationsException 
MESSAGE: Communications link failure 

>Last packet sent to the server was 43 ms ago. 

>STACKTRACE: 

>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 

>Last packet sent to the server was 43 ms ago. 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) 
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) 
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985) 
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414) 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) 
at com.m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per the error stacktrace, your connection to MySQL server is lost.

>root cause 

>com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
  No operations allowed after connection closed.
  Connection was implicitly closed due to underlying exception/error: 

** BEGIN NESTED EXCEPTION ** 
    >com.mysql.jdbc.exceptions.jdbc4.CommunicationsException 
MESSAGE: Communications link failure 

>Last packet sent to the server was 43 ms ago. 

>STACKTRACE: 

>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 

It is very clear that the root cause is Communications link failure.

Try pinging your database server and see if you are able to connect.
Else resolve the network issue and then connect. No alternatives for this.

You can issue a light weight ping to your database server to check the connection availability.
Please read following discussion and articles:

  1. Ping MySQL Server
  2. Ping syntax and example

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...