gpt4 book ai didi

java - jdbc 开始失败

转载 作者:行者123 更新时间:2023-12-01 19:04:28 26 4
gpt4 key购买 nike

访问 Web 服务时,我会随机收到此错误。很难复制,一旦刷新,一切都会按预期运行。

      Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)        at org.hibernate.loader.Loader.doList(Loader.java:2235)        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)        at org.hibernate.loader.Loader.list(Loader.java:2124)        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)        at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)        at edu.asd.myproj.hibernate.adapter.CriteriaAdapter.list(CriteriaAdapter.java:380)        at edu.asd.myproj.DaoHibernateImpl.findByCriteria(DaoHibernateImpl.java:778)        at edu.asd.myproj.DaoHibernateImpl.findByCriteria(DaoHibernateImpl.java:765)        at edu.asd.myproj.DaoHibernateImpl.findByProperty(DaoHibernateImpl.java:361)        at edu.asd.myproj.ProfilesDaoImpl.count(ProfilesDaoImpl.java:81)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:597)        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)        at $Proxy27.count(Unknown Source)        at edu.asd.myproj.ResourceProfileLoaderNew.loadProfiles(ResourceProfileLoaderNew.java:66)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:597)        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:297)        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:250)        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:144)        ... 50 more    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was44323 seconds ago.The last packet sent successfully to the server was 44323 seconds ago, which  is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.        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.send(MysqlIO.java:3246)        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)        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.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)        at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)        at org.hibernate.loader.Loader.doQuery(Loader.java:697)        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)        at org.hibernate.loader.Loader.doList(Loader.java:2232)        ... 79 more    Caused by: java.net.SocketException: Broken pipe        at java.net.SocketOutputStream.socketWrite0(Native Method)        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)        ... 90 more

This is my hibernate.properties file

# Turn on for SQL debugging
hibernate.show_sql=true

# Generate schema?
hibernate.hbm2ddl.auto=validate

#============================================================
# C3P0 connection pool configuration
#============================================================
#changed to default values
c3p0.acquireIncrement=hibernate.c3p0.acquire_increment
c3p0.idleConnectionTestPeriod=hibernate.c3p0.idle_test_period
c3p0.initialPoolSize=10
c3p0.maxIdleTime=hibernate.c3p0.timeout
c3p0.maxPoolSize=hibernate.c3p0.max_size
c3p0.maxStatements=hibernate.c3p0.max_statements
c3p0.minPoolSize=hibernate.c3p0.min_size
c3p0.testConnectionsOnCheckout=hibernate.c3p0.validate

该错误随机出现一次,需要很长时间才会再次出现。刷新后就会消失。

最佳答案

请发送完整的异常堆栈跟踪,以便读者更好地理解。

此异常通常在数据库连接失效时发生。

过时意味着:连接已被服务器终止,但仍被池视为 Activity 连接。您需要在连接中配置连接测试。对于 C3P0 中的这种方法,您必须使用以下配置:

c3p0.testConnectionOnCheckin = true
testConnectionOnCheckout= true

为了进行更多检查,请增加结帐超时,如下所示:

c3p0.checkoutTimeout = 0

并在C3P0中测试另一个测试选项,例如:

  • connectionTesterClassName
  • idleConnectionTestPeriod
  • 自动测试表
  • preferredTestQuery

另一种测试方法是编写示例代码并通过 JDBC pure 代码连接到数据库。(通过 DriverManagerConnection 等)

关于java - jdbc 开始失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10658473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com