Jump to content
JasperReports Library 7.0 is now available ×

Passing JDBC Connection


2004 IR Help

Recommended Posts

By: Eric - netizen1

Passing JDBC Connection

2004-07-14 11:20

I have a report that uses a JDBC Connection. I used iReport to create it and it works great within the gui.

But when i run the application and pass the Connection i get a blank pdf. But if i pass a JREmptyDataSource the pdf has the text (except the database query result).

 

I read somewhere that using iReport they had to do a change but it didnt mention what.

 

Here is my report jrxml:

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd";>

<jasperReport

name="AdverseActionLetter"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="612"

pageHeight="792"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

scriptletClass="AdverseActionLetterScriplet"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="2" />

<parameter name="Application_Id" isForPrompting="true" class="java.lang.Integer">

<defaultValueExpression ><![CDATA[new Integer(973250)]]></defaultValueExpression>

</parameter>

<parameter name="RoadLoans_Report_Home" isForPrompting="false" class="java.lang.String">

<defaultValueExpression ><![CDATA[new String("C:/eclipse-3.0/workspace")

]]></defaultValueExpression>

</parameter>

<queryString><![CDATA[select top 1 a.Application_Id as AppId, c.First_Name as FirstName, c.Middle_Name as Mi, c.Customer_Name as LastName,

e.Address1 as Address, f.City as City,

f.State as State, f.Zip_Code as Zip,

g.CB_Office as CBOffice, g.CB_Addr1 as CBAddress, g.CB_City as CBCity, g.CB_State as CBState, g.CB_Zip as CBZip,

g.CB_Phone as CBPhone

from d_Application a

left outer join d_Customer_Detail b on b.application_id = a.application_id

left outer join l_Customer c on c.Customer_Id = b.Customer_Id

left outer join d_Customer_Address d on d.Customer_Id = b.Customer_Id

left outer join l_Address e on e.Address_Id = d.Address_Id

left outer join l_City_Zip f on f.City_Zip_Id = e.City_Zip_Id

left outer join w_Credit_Summary g on ( g.Customer_Id = b.Customer_Id and g.Application_Id = a.Application_Id)

where

a.application_id = $P{Application_Id}]]></queryString>

<field name="AppId" class="java.lang.Integer"/>

<field name="FirstName" class="java.lang.String"/>

<field name="Mi" class="java.lang.String"/>

<field name="LastName" class="java.lang.String"/>

<field name="Address" class="java.lang.String"/>

<field name="City" class="java.lang.String"/>

<field name="State" class="java.lang.String"/>

<field name="Zip" class="java.lang.String"/>

<field name="CBOffice" class="java.lang.String"/>

<field name="CBAddress" class="java.lang.String"/>

<field name="CBCity" class="java.lang.String"/>

<field name="CBState" class="java.lang.String"/>

<field name="CBZip" class="java.lang.String"/>

<field name="CBPhone" class="java.lang.String"/>

<variable name="AppIds" class="java.lang.Integer" resetType="Report" calculation="Nothing">

<variableExpression><![CDATA[new Integer(3396504)]]></variableExpression>

</variable>

<background>

<band height="0" isSplitAllowed="false" >

</band>

</background>

<title>

<band height="197" isSplitAllowed="false" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="0"

y="145"

width="243"

height="18"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-14"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{Address}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="0"

y="127"

width="328"

height="18"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-26"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[((AdverseActionLetterScriplet)$P{REPORT_SCRIPTLET}).formatName($F{FirstName}, $F{Mi}, $F{LastName})]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="0"

y="163"

width="341"

height="14"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-85"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[((AdverseActionLetterScriplet)$P{REPORT_SCRIPTLET}).formatAddress($F{City}, $F{State}, $F{Zip} )]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="390"

y="110"

width="162"

height="18"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-87"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[new String("Reference No. " + String.valueOf($P{Application_Id}))]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement

mode="Opaque"

x="390"

y="96"

width="152"

height="14"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-17"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[((AdverseActionLetterScriplet)$P{REPORT_SCRIPTLET}).dateFormat()]]></textFieldExpression>

</textField>

</band>

</title>

<pageHeader>

<band height="38" isSplitAllowed="false" >

</band>

</pageHeader>

<columnHeader>

<band height="26" isSplitAllowed="false" >

</band>

</columnHeader>

<detail>

<band height="17" isSplitAllowed="false" >

<subreport isUsingCache="true">

<reportElement

mode="Opaque"

x="337"

y="-38"

width="0"

height="0"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-10"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

</subreport>

</band>

</detail>

<columnFooter>

<band height="304" isSplitAllowed="false" >

</band>

</columnFooter>

<pageFooter>

<band height="109" isSplitAllowed="false" >

<staticText>

<reportElement

mode="Opaque"

x="3"

y="15"

width="548"

height="78"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-3"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<text><![CDATA[The Federal Equal Credit Opportunity Act prohibits creditors from discriminating against credit applicants on

the basis of race, color, religion, national origin, sex, marital status, age (provided that the applicant has the

capacity to enter into a binding contract); because all or part of the applicant's income derives from any

public assistance program; or because the applicant has in good faith exercised any right under the

Consumer Credit Protection Act. The Federal Agency that administers compliance with this law concerning

this creditor is the Federal Trade Commission, Equal Credit Opportunity, Washington D.C., 20580.]]></text>

</staticText>

</band>

</pageFooter>

<summary>

<band height="0" isSplitAllowed="false" >

</band>

</summary>

</jasperReport>

 

 

Here is the code i used to give it a connection:

public boolean generatePDFREports(Integer applicationId)

{

boolean blResult = false;

Map parameters = null;

JasperReport jasperReport = null;

JasperPrint jasperPrint = null;

Connection conn = null;

 

try

{

String strBuff = null;

 

strBuff = "c:/eclipse-3.0/workspace/roadloans.letters";

 

 

JasperCompileManager.compileReportToFile( strBuff + "/AdverseActionLetter.jrxml");

JasperCompileManager.compileReportToFile( strBuff + "/AdverseActionLetterStipulations.jrxml");

 

Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();

conn = DriverManager.getConnection( "jdbc:jtds:sqlserver://localhost:1433/Daytona;user=xx;password=xx";, "xx", "xx" );

if(conn == null)

System.out.println("Connection is null");

if(conn.isClosed() == false)

{

 

 

parameters = new HashMap();

parameters.put("Application_Id", applicationId);

parameters.put("RoadLoans_Report_Home", strBuff);

parameters.put("REPORT_CONNECTION", conn);

 

 

jasperReport = (JasperReport)JRLoader.loadObject(strBuff + "/AdverseActionLetter.jasper");

jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn );

pdfOutput = new File(strBuff + "/advers_test.pdf");

JasperExportManager.exportReportToPdfFile(jasperPrint, pdfOutput.toString());

 

 

 

conn.close();

..

}

 

Thanks in advance.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...