我用jasperreports +struts2做报表系统,数据源是JDBC连接,不知道有做过类似的没有?你们的数据库连接是怎么关闭的,我是修改JasperReportsResult类的源代码来控制的,我想jasper这么流行的一个框架,在数据库连接关闭方面应该还是会注意的吧,我没有找到其他关闭的方法。struts报表jdbc

解决方案 »

  1.   

    c3p0啊,关键是和struts2整合,
      

  2.   

    struts2配置
    <package name="default" namespace="/jasper"
    extends="struts-default,jasperreports-default">
    <action name="dyreport" class="com.jrzy.platform.struts.dyreport.DyReportAction">
    <result name="success" type="jasper">
    <param name="location">${location}</param>
    <param name="imageServletUrl">/img/</param>
    <param name="connection">conn</param>
    <param name="format">${format}</param>
    <param name="reportParameters">params</param> 
    </result>
    </action>
    <action name="queryparam" class="com.jrzy.platform.struts.dyreport.QueryParamAction">
    <result name="success">/report.jsp</result>
    </action>
    </package>
    spring配置
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="execute*" read-only="true" />
    <tx:method name="find*" read-only="true" />
    <tx:method name="get*" read-only="true" />
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="do*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="del*" propagation="REQUIRED" />
    <tx:method name="Read*" propagation="REQUIRED" />
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="allManagerMethod"
    expression="execution(* com.jrzy.platform.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
    </aop:config>
    <!-- jdbc配置文件 -->
    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:resource/jdbc.properties</value>
    </list>
    </property>
    </bean>
    <!-- 数据源配置 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${diriver.class}">
    </property>
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="initialPoolSize" value="${cpool.minPoolSize}" />
    <property name="minPoolSize" value="${cpool.minPoolSize}" />
    <property name="acquireIncrement" value="${cpool.acquireIncrement}" />
    </bean>
      

  3.   

    这个貌似是不要关闭的吧,你太小看spring的事物管理了吧;直接给它就妥妥的了
      

  4.   

    destroy-method="close"有这句话 就行了, spring会自己关闭
      

  5.   

    我是说jasper啊,我将jdbc的connection传递给
    org.apache.struts2.views.jasperreports.JasperReportsResult了,jasperreport底层代码已经超出了spring的控制范围,如果不手动关闭连接,一下就耗费完数据库了,最后只有改org.apache.struts2.views.jasperreports.JasperReportsResult的源代码了,我在doExceute方法最后try catch finallycatch (Exception e) {
    throw e;
    } finally {
    if (conn != null)
    LOG
    .debug("关闭数据库连接");
    conn.close();
    }
    这样就关闭了