问题描述
用ssh做的系统,每隔24小时,系统就登不上了,重启一下服务器又登上了,查看tomcat日志,错误提示org.springframework.jdbc.UncategorizedSQLException:Hibernateoperation:Cannotopenconnection;uncategorizedSQLExceptionforSQL[???];SQLstate[null];errorcode[0];com.mchange.v2.c3p0.PoolBackedDataSource@1a9883d[connectionPoolDataSource->com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@704cf5[acquireIncrement->3,acquireRetryAttempts->30,acquireRetryDelay->1000,autoCommitOnClose->false,automaticTestTable->null,breakAfterAcquireFailure->false,checkoutTimeout->0,connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,factoryClassLocation->null,forceIgnoreUnresolvedTransactions->false,identityToken->704cf5,idleConnectionTestPeriod->100,initialPoolSize->3,maxIdleTime->100,maxPoolSize->100,maxStatements->150,maxStatementsPerConnection->0,minPoolSize->3,nestedDataSource->com.mchange.v2.c3p0.DriverManagerDataSource@1e2481b[description->null,driverClass->null,factoryClassLocation->null,identityToken->1e2481b,jdbcUrl->jdbc:mysql://localhost:3306/jianguan,properties->{useUnicode=true,user=******,password=******,autocommit=true,characterEncoding=GBK}],preferredTestQuery->null,propertyCycle->300,testConnectionOnCheckin->false,testConnectionOnCheckout->false,usesTraditionalReflectiveProxies->false],factoryClassLocation->null,identityToken->1a9883d,numHelperThreads->3]hasbeenclosed()--youcannolongeruseit.;nestedexceptionisjava.sql.SQLException:com.mchange.v2.c3p0.PoolBackedDataSource@1a9883d[connectionPoolDataSource->com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@704cf5[acquireIncrement->3,acquireRetryAttempts->30,acquireRetryDelay->1000,autoCommitOnClose->false,automaticTestTable->null,breakAfterAcquireFailure->false,checkoutTimeout->0,connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,factoryClassLocation->null,forceIgnoreUnresolvedTransactions->false,identityToken->704cf5,idleConnectionTestPeriod->100,initialPoolSize->3,maxIdleTime->100,maxPoolSize->100,maxStatements->150,maxStatementsPerConnection->0,minPoolSize->3,nestedDataSource->com.mchange.v2.c3p0.DriverManagerDataSource@1e2481b[description->null,driverClass->null,factoryClassLocation->null,identityToken->1e2481b,jdbcUrl->jdbc:mysql://localhost:3306/jianguan,properties->{useUnicode=true,user=******,password=******,autocommit=true,characterEncoding=GBK}],preferredTestQuery->null,propertyCycle->300,testConnectionOnCheckin->false,testConnectionOnCheckout->false,usesTraditionalReflectiveProxies->false],factoryClassLocation->null,identityToken->1a9883d,numHelperThreads->3]hasbeenclosed()--youcannolongeruseit.atorg.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)atorg.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)atorg.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)atorg.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)atorg.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)atorg.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)atbean.managers.UserMananger.userLogin(UserMananger.java:28)atuser.servlet.LoginServlet.doGet(LoginServlet.java:59)atuser.servlet.LoginServlet.doPost(LoginServlet.java:104)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:637)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)atjava.lang.Thread.run(UnknownSource)提示信息貌似是数据库连不上了,为什么重启下服务器就正常了,小弟在这困了好长时间了。hinernate配置文件;<!DOCTYPEhibernate-configurationPUBLIC"-//Hibernate/HibernateConfigurationDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><propertyname="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="hibernate.connection.url">jdbc:mysql://localhost:3306/jianguan</property><propertyname="hibernate.connection.username">root</property><propertyname="hibernate.connection.password">root</property><propertyname="connection.useUnicode">true</property><propertyname="connection.characterEncoding">GBK</property><propertyname="connection.autocommit">true</property><propertyname="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property><propertyname="hibernate.show_sql">false</property><propertyname="current_session_context_class">thread</property><propertyname="hibernate.jdbc.batch_size">23</property><propertyname="hibernate.connection.pool_size">20</property><propertyname="hibernate.current_session_context_class">thread</property></session-factory></hibernate-configuration>spring配置文件<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scanbase-package="newpackage"/><beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><propertyname="configLocation"><value>classpath:hibernate.cfg.xml</value></property><propertyname="hibernateProperties"><props><propkey="hibernate.show_sql">false</prop><propkey="hibernate.dbcp.maxActive">100</prop><propkey="hibernate.dbcp.whenExhaustedAction">1</prop><propkey="hibernate.dbcp.maxWait">1200</prop><propkey="hibernate.dbcp.maxIdle">10</prop></props></property></bean><beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><propertyname="sessionFactory"><refbean="sessionFactory"/></property></bean><tx:annotation-driventransaction-manager="transactionManager"/></beans>求大侠给看看哪里出的问题,谢谢了
解决方案
解决方案二:
是不是连接没有释放你看看是什么占了连接
解决方案三:
猜测是数据库连接池配置的问题。记得Spring3.x企业应用开发实战书中讲数据库连接池时,举了一个例子,是mysql配置的例子,好像就是因数据库连接池配置不当导致mysql长时间过后就无法连接。