我做一个很简单的报表系统, 也写了一个很简单的jdbc连接数据库程序。
每次在第一次执行查询的时候都会报错误:(但是在执行第二次查询的时候就没有问题了,之后都没有问题。就是在隔了一段时间后每次第一次查询会报错)
INFO [http-8080-Processor46] cn.com.zjtelecom.cr.util.JDBCUtils - sql=select a.integralmonth,b.integralyear from (select sum(h.dp_pub) + sum(h.dp_gov) + sum(h.df_pub) + sum(h.df_gov) + sum(h.hd_pub) + sum(h.hd_gov) as integralmonth from hb_jf_rpt h where h.rtp_month >= '200801' and h.rtp_month <= '200800') a,(select 0 as integralyear from dual) b ERROR [http-8080-Processor46] cn.com.zjtelecom.cr.util.JDBCUtils - 查询数据库时出错!<sql=select a.integralmonth,b.integralyear="" from="" (select="" sum(h.dp_pub)="" +="" sum(h.dp_gov)="" +="" sum(h.df_pub)="" +="" sum(h.df_gov)="" +="" sum(h.hd_pub)="" +="" sum(h.hd_gov)="" as="" integralmonth="" from="" hb_jf_rpt="" h="" where="" h.rtp_month="">= '200801' and h.rtp_month <= '200800') a,(select 0 as integralyear from dual) b> java.sql.SQLException: Io 异常: Connection reset at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:389) at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:413) at oracle.jdbc.driver.OracleConnection.privateCreateStatement(OracleConnection.java:769) at oracle.jdbc.driver.OracleConnection.createStatement(OracleConnection.java:734) at cn.com.zjtelecom.cr.util.JDBCUtils.query2Bean(JDBCUtils.java:65) at cn.com.zjtelecom.cr.service.impl.ReportService.report(ReportService.java:19) at cn.com.zjtelecom.cr.action.haobai.JiFenHuiZongAction.report(JiFenHuiZongAction.java:47) 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:585) at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:358) at com.opensymphony.xwork.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:218) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:192) at com.opensymphony.xwork.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:115) at com.opensymphony.xwork.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.webwork.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:174) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.webwork.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:169) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:151) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:186) at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190) at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116) at com.opensymphony.webwork.dispatcher.DispatcherUtils.serviceAction(DispatcherUtils.java:273) at com.opensymphony.webwork.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:202) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at cn.com.zjtelecom.sso.client.filter.SSOFilter.doFilter(SSOFilter.java:366) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Thread.java:595)
不知道大家有什么看法
public static Connection openConnectInstance() { try { if (conn != null && !conn.isClosed()) { return conn; } Class.forName(driverName).newInstance(); conn = DriverManager.getConnection(dbURL, dbUser, dbPassword); conn.setAutoCommit(false); } catch (Exception e) { if (log.isErrorEnabled()) log.error("创建数据库连接时出错!", e); conn = null; } return conn; } public static void closeConnectionInstance() throws SQLException { if (conn != null && !conn.isClosed()) { conn.close(); } conn = null; }