Subreport - Close connection

0

Hi,

my subreport connects successfully to a different database, by the description of ntatlock.

Like:

<subreport>
    <reportElement mode="Opaque" x="555" y="0" width="5" height="20"/>
    <subreportParameter name="P_B">
        <subreportParameterExpression><![CDATA[$F{username}]]></subreportParameterExpression>
    </subreportParameter>
    <connectionExpression><![CDATA[java.sql.DriverManager.getConnection($P{P_SUB_DATASOURCE}.getConnectionUrl(),$P{P_SUB_DATASOURCE}.getUsername(),$P{P_SUB_DATASOURCE}.getPassword())]]></connectionExpression>
    <returnValue subreportVariable="V_M" toVariable="V_M"/>
    <subreportExpression><![CDATA["repo:0001_Subreport.jrxml"]]></subreportExpression>
</subreport>

But the connection is not closing. So what can I do, to close the connection?

ernst_2's picture
154
Joined: Feb 17 2015 - 1:15am
Last seen: 3 years 11 months ago

1 Answer:

0

Found it!

<parameter name="P_SUB_DATASOURCE" class="com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource" isForPrompting="false">
    <defaultValueExpression><![CDATA[com.jaspersoft.jasperserver.api.engine.jasperreports.util.RepositoryUtil.getThreadRepositoryContext().getRepository().getResource(null,"/<path to data source>/")]]></defaultValueExpression>
</parameter>
<parameter name="P_SUB_CONNECTION" class="java.sql.Connection" isForPrompting="false">
    <defaultValueExpression><![CDATA[java.sql.DriverManager.getConnection($P{P_SUB_DATASOURCE}.getConnectionUrl(),$P{P_SUB_DATASOURCE}.getUsername(),$P{P_SUB_DATASOURCE}.getPassword())]]></defaultValueExpression>
</parameter> 
<subreport>
    <reportElement mode="Opaque" x="555" y="0" width="5" height="20"/>
    <subreportParameter name="P_B">
        <subreportParameterExpression><![CDATA[$F{user}]]></subreportParameterExpression>
    </subreportParameter>
    <connectionExpression><![CDATA[$P{P_SUB_CONNECTION}]]></connectionExpression>
    <returnValue subreportVariable="V_M" toVariable="V_M"/>
    <subreportExpression><![CDATA["repo:0001_Subreport.jrxml"]]></subreportExpression>
</subreport>
<textField>
    <reportElement x="555" y="10" width="5" height="20"/>
    <textElement verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[""; $P{P_SUB_CONNECTION}.close()]]></textFieldExpression>
</textField>

ernst_2's picture
154
Joined: Feb 17 2015 - 1:15am
Last seen: 3 years 11 months ago
Feedback