本帖最后由 tuanjie 于 2014-1-12 12:57 编辑
最近使用C3P0数据源实现数据库的操作时,才开始没有什么问题,对数据库的增、删、改、查都可以正常运行,但是运行一段时间后,就报了一下异常,连接数据库失败,其中异常信息为:
- 严重: Servlet.service() for servlet [CheckTeacherServlet] in context with path [/hactcmOAMS] threw exception
- com.hactcm.oams.exception.DaoException: java.sql.SQLException: Connections could not be acquired from the underlying database!
- at com.hactcm.oams.dbc.DatabaseConnection.getConnection(DatabaseConnection.java:34)
- at com.hactcm.oams.dao.proxy.OAMSDAOProxy.<init>(OAMSDAOProxy.java:15)
- at com.hactcm.oams.dao.factory.OAMSDAOFactory.getOAMSDAOInstance(OAMSDAOFactory.java:16)
- at com.hactcm.oams.service.impl.OAMSServiceImpl.<init>(OAMSServiceImpl.java:18)
- at com.hactcm.oams.service.proxy.OAMSServiceProxy.<init>(OAMSServiceProxy.java:20)
- at com.hactcm.oams.service.factory.OAMSServiceFactory.getOAMSService(OAMSServiceFactory.java:19)
- at com.hactcm.oams.manager.ajaxServlet.CheckTeacherServlet.doGet(CheckTeacherServlet.java:26)
- at com.hactcm.oams.manager.ajaxServlet.CheckTeacherServlet.doPost(CheckTeacherServlet.java:43)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at com.hactcm.oams.filter.role.LoginRoleFilter.doFilter(LoginRoleFilter.java:22)
- at com.hactcm.oams.filter.HttpFilter.doFilter(HttpFilter.java:33)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at com.hactcm.oams.filter.character.CharacterFilter.doFilter(CharacterFilter.java:27)
- at com.hactcm.oams.filter.HttpFilter.doFilter(HttpFilter.java:33)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
- at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
- at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
- at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
- at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)
- at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
- at java.lang.Thread.run(Thread.java:744)
- Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
- at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
- at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:689)
- at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
- at com.hactcm.oams.dbc.DatabaseConnection.getConnection(DatabaseConnection.java:29)
- ... 37 more //这里是我自己写的DatabaseConnection类
复制代码
而我的c3p0-config.xml文件的内容是:
- <?xml version="1.0" encoding="UTF-8"?>
- <c3p0-config>
- <default-config>
- <property name="initialPoolSize">10</property>
- <property name="maxPoolSize">15</property>
- <property name="driverClass">com.mysql.jdbc.Driver</property>
- <property name="jdbcUrl">jdbc:mysql://localhost:3306/oetqms</property>
- <property name="user">root</property>
- <property name="password">123456</property>
- </default-config>
- </c3p0-config>
复制代码 连接数据库的类是DatabaseConnection.java
每次出现异常,都指向这句代码conn = ds.getConnection();,这句代码的意思是从数据源中取出一个Connection对象。
每次出现异常后重新启动tomcat服务器就没有问题了,运行一段时间又出现相同的问题,这是什么原因啊?
|
|