异常日志信息:
[2013-04-18 20:13:08] WARN [http-pas-9999-20$161385442] (JDBCExceptionReporter.java:100) - SQL Error: 0, SQLState: null
[2013-04-18 20:13:08] ERROR [http-pas-9999-20$161385442] (JDBCExceptionReporter.java:101) - An attempt by a client to checkout a Connection has timed out.
[2013-04-18 20:13:08] WARN [http-pas-9999-20$161385442] (JDBCExceptionReporter.java:100) - SQL Error: 0, SQLState: null
[2013-04-18 20:13:08] ERROR [http-pas-9999-20$161385442] (JDBCExceptionReporter.java:101) - An attempt by a client to checkout a Connection has timed out.
[2013-04-18 20:13:08] ERROR [http-pas-9999-20$161385442] (GetVideoFileMD5Servlet.java:60) - GetVideoFileMD5Servlet error null
java.lang.NullPointerException
at com.hunthawk.framework.HibernateGenericController.executeQuerySQL(HibernateGenericController.java:652)
at com.hunthawk.reader.service.videoTask.impl.VideoTaskFileImplService.getTargetFileMd5(VideoTaskFileImplService.java:379)
at com.hunthawk.reader.service.videoTask.impl.VideoTaskFileImplService$$FastClassByCGLIB$$3d517436.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
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.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.hunthawk.reader.service.videoTask.impl.VideoTaskFileImplService$$EnhancerByCGLIB$$49109a1d.getTargetFileMd5(<generated>)
at com.hunthawk.reader.servlet.GetVideoFileMD5Servlet.process(GetVideoFileMD5Servlet.java:56)
at com.hunthawk.reader.servlet.GetVideoFileMD5Servlet.doGet(GetVideoFileMD5Servlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
问题问下: 刚开是以为是数据库账号有问题,导致不能连接,但是重启服务器之后就可以了,系统跑一会之后,就会出现连接超时的问题,最后看了下代码
代码如下:
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if(rs != null){
rs.close();
}
if(smt != null){
smt.close();
}
if(conn != null){
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
session.close();
在finally 中关闭数据库连接,开始在finally中没有判断 rs,smt,conn 是否为空,直接关闭,后来发现有与查询的时候数据表名写错了,导致rs 对象为空,所以后面数据连接就没有关闭,这样创建的数据库连接越来越多,没有被释放,导致后面不能创建新的连接。