问题描述
我使用Struts2 + JSP + Tomcat6 + Hibernate + Mysql作为我的J2EE应用程序框架。以下为主题,我有这个错误的问题:
org.hibernate.exception.JDBCConnectionException:无法执行查询
这似乎是由于事实上,MySQL在n小时后关闭它的连接。
当人们回答了我改变了休眠配置,以通过JNDI获得我的数据库连接。这是我采取的行动方式:
我的hibernate.cfg.xml:
< hibernate-configuration>
< session-factory>
< property name =connection.datasource> java:comp / env / jdbc / hposg< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =show_sql> true< / property>
< property name =current_session_context_class>线程< / property>
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
< property name =hbm2ddl.auto>更新< / property>
< property name =hibernate.max_fetch_depth> 3< / property>
< / session-factory>
< / hibernate-configuration>
我放入META-INF的context.xml文件:
<上下文>
< Resource name =jdbc / hposg
global =jdbc / hposg
auth =Container
type =javax.sql.DataSource
username =root
password =
driverClassName =com.mysql.jdbc.Driver
url =jdbc:mysql:// localhost:3306 / hposg?autoReconnect = true& amp; characterEncoding = UTF-8
maxActive =8
maxIdle =4/>
< / Context>
以及web.xml中的这些修改:
<资源引用>
< description> DB Connection< / description>
< res-ref-name> jdbc / hposg< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< res-auth>容器< / res-auth>
< / resource-ref>
奇怪的是我还是得到了同样的错误!这里是stacktrace:
'org.hibernate.exception.JDBCConnectionException:无法在org.hibernate中执行查询
.conception(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader .java:2297)
在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
在org.hibernate.loader.Loader.list(Loader.java:2167)
在org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org。 hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl。 list(QueryImpl.java:102)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
at com.hposg.domain.HPOSG.getPlayerByID(HPOSG.java:117)
at com.hposg.login.UserSession.getPlayerById(UserSession.java:39)
at com.hposg.controller.struts .PortfolioLoadAction.execute(PortfolioLoadAction.java:72)
在sun.reflect.GeneratedMethodAccessor1032.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:616)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
at com.opensymphony.xwork2.DefaultActionInvocation .invokeActionOnly(DefaultActionInvocation.java:280)
在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
在com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java :165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFil terInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
。在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
在com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
在com.opensymphony .xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor .intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java :195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
在com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
在org.apache。 struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor。截距(CheckboxIntercepto r.java:94)美元,com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237 B $ B)
在org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com .opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
在com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
在com.opensymphony.xwork2.DefaultActionInvocation .invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation .java:237)
在com.opensym phony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
处com.opensymphony.xwork2.interceptor com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
。 PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
在com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation。 Java的:在com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165 237)
)
在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony .xwork2.interceptor.AliasInterceptor.intercept( (com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176))
在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
在org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
。在组织.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina .core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve .invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(St andardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)$ b $在java.lang.Thread.run(Thread.java:636)
引起:com .mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
发送到服务器的最后一个数据包是0 ms前。
在sun.reflect.GeneratedConstructorAccessor109.newInstance(来源不明)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(
at com.mysql.jdbc.Util.handleNewInstance(Util.java:353)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
在com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2720)
在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1582)
在com.mysql.jdbc .MysqlIO.sqlQueryDirect(MysqlIO.java:1710)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2436)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java :1402)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1556)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
在org.hib ernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
at org.hibernate.loader.Loader.doQuery( Loader.java:718)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
... 74 more
由java.net.SocketException引起的损坏:java.net.SocketOutputStream.socketWrite0中的管道
(Native方法)$ java.net.SocketOutputStream.socketWrite中的
(SocketOutputStream.java:109)
在java.net.SocketOutputStream.write(SocketOutputStream.java:153)
在java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
。在java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2703)
... 85 more
'
我对context.xml做了一些修改a nd问题似乎已解决:
maxActive = - 1
maxIdle =30
validationQuery =SELECT 1
testWhileIdle =true
尽管我之前提到过这些修改,但不幸的是我仍然遇到同样的错误。任何想法?
在Tomcat6 + Hibernate + MySQL的生产系统中(和我们的例子中的Spring一样)我们发现的唯一可靠解决方案是在MySQL配置中将连接超时设置为一个很大的值。我不记得具体情况,但我认为验证后,底层代码存在问题该池资源是有效的。
我们没有尝试的另一种可能性是使用除DBCP之外的备用连接池机制。下一步尝试将
I use Struts2+JSP+Tomcat6+Hibernate+Mysql as my J2EE application framework.Following to this topic, I've had the problem of getting this error:
org.hibernate.exception.JDBCConnectionException: could not execute query
It appears to be due to the fact that mysql closes it's connections after n hours.As people answered there I changed the hibernate config to get my db connections through JNDI.here is the course of actions which I've taken to do this:
my hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/hposg</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.max_fetch_depth">3</property>
<!-- Mapping files -->
</session-factory>
</hibernate-configuration>
the context.xml file that I've put in META-INF derictory:
<Context>
<Resource name="jdbc/hposg"
global="jdbc/hposg"
auth="Container"
type="javax.sql.DataSource"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/hposg?autoReconnect=true&characterEncoding=UTF-8"
maxActive="8"
maxIdle="4"/>
</Context>
and these modifications in web.xml:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/hposg</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Strangely enough I still get the same error! here is the stacktrace:
'org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2297)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
at com.hposg.domain.HPOSG.getPlayerByID(HPOSG.java:117)
at com.hposg.login.UserSession.getPlayerById(UserSession.java:39)
at com.hposg.controller.struts.PortfolioLoadAction.execute(PortfolioLoadAction.java:72)
at sun.reflect.GeneratedMethodAccessor1032.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:636)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.GeneratedConstructorAccessor109.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:353)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2720)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1582)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1710)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2436)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1402)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1556)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
at org.hibernate.loader.Loader.doQuery(Loader.java:718)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
... 74 more
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2703)
... 85 more
'
[EDIT]I made a few changes to the context.xml and the problem seems to be solved:
maxActive="-1"
maxIdle="30"
validationQuery="SELECT 1"
testWhileIdle="true"
[EDIT_2]Despite the modifications I mentioned before, unfortunately I'm still getting the same error. Any Ideas?
We had the same issue in a production system with Tomcat6+Hibernate+MySQL (and Spring in our case) and the only reliable solution we found was to set the connection timeout to a large value in the MySQL configuration. I cannot remember the particulars but I believe there was an issue with the underlying commons-pool code when it verifies that pooled resource is valid.
Another possibility that we did not try was to use an alternate Connection Pooling mechanism other than DBCP. Next to try would be C3PO
这篇关于获取org.hibernate.exception.JDBCConnectionException:即使通过JNDI也无法执行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!