zjian0573 2008-12-16 14:25
浏览 182
已采纳

一个困挠很久的jdbc连接问题,请解惑

我做一个很简单的报表系统, 也写了一个很简单的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;
    }
  • 写回答

1条回答 默认 最新

  • iteye_5200 2008-12-16 16:10
    关注

    应该是代码问题,能否给出上面代码的完整版

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串