Jump to content
We've recently updated our Privacy Statement, available here ×

How to display dash line from mysql database with ireport


anwarzamal25

Recommended Posts

i want to display dash ("-") from database those column value will be Zero.


Consider there is a table Employee which has 4 columns EmpId , EmpFirstName , EmpSecondName, EmpAge


 
EmpId      EmpFirstName    EmpSecondName   EmpAge
 

101            Jackson            Bilson                        45

102            Willson                                               25
103            Barley                                                23  

 
output:

EmpId      EmpFirstName    EmpSecondName   EmpAge

101            Jackson            Bilson                        45
102            Willson                 --                              25
103            Barley                   --                             23  


 
my XML source code is here     

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="sample" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="0" uuid="e6f67a14-570a-4046-9ab3-

52cbb2cb9d36">
    <property name="ireport.zoom" value="2.0"/>
    <property name="ireport.x" value="8"/>
    <property name="ireport.y" value="626"/>
    <style name="Title" fontName="Serif" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
    <style name="SubTitle" forecolor="#666666" fontName="Serif" fontSize="18"/>
    <style name="Column header" forecolor="#FFFFFF" fontName="Serif" fontSize="12" isBold="true"/>
    <style name="Detail" fontName="Serif" fontSize="12"/>
    <queryString>
        <![CDATA[sELECT * FROM Employee;]]>
    </queryString>
    <field name="EmployeeId" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="EmployeeFirstName" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="EmployeeSecondName" class="java.lang.String">
        <fieldDescription><![CDATA["$F{EmployeeSecondName}.equals("0") ? "--" : $F{EmployeeSecondName}"]]></fieldDescription>
    </field>
    <field name="EmployeeAge" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <variable name="EmployeeSecondName_1" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeSecondName}]]></variableExpression>
    </variable>
    <variable name="EmployeeId_1" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
    </variable>
    <variable name="EmployeeId_2" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
    </variable>
    <variable name="EmployeeId_3" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
    </variable>
    <variable name="EmployeeId_4" class="java.lang.Integer" calculation="System">
        <variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
    </variable>
    <variable name="EmployeeId_5" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
    </variable>
    <variable name="EmployeeFirstName_1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{EmployeeFirstName}]]></variableExpression>
    </variable>
    <group name="Group1">
        <groupExpression><![CDATA[(int)($V{REPORT_COUNT}/15)]]></groupExpression>
        <groupHeader>
            <band height="40">
                <staticText>
                    <reportElement x="12" y="13" width="100" height="20" uuid="3aeea084-6d27-457c-bb0e-5d455609fcde"/>
                    <textElement>
                        <font fontName="Serif" size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA["EmployeeId"]]></text>
                </staticText>
                <staticText>
                    <reportElement x="146" y="10" width="177" height="20" uuid="664c98ba-24b9-4c87-8e86-eac17066a4e3"/>
                    <textElement>
                        <font fontName="Serif" size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA["EmployeeFirstName"]]></text>
                </staticText>
                <staticText>
                    <reportElement x="426" y="13" width="168" height="20" uuid="f461036a-e9a0-4c21-9d7d-2a307e83a6d5"/>
                    <textElement>
                        <font fontName="Serif" size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA["EmployeeSecondName""]]></text>
                </staticText>
                <staticText>
                    <reportElement x="671" y="13" width="106" height="20" uuid="959acc83-336f-4941-98c6-6b860f628bd7"/>
                    <textElement>
                        <font fontName="Serif" size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA["EmployeeAge"]]></text>
                </staticText>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="30">
                <frame>
                    <reportElement mode="Opaque" x="652" y="0" width="150" height="30" forecolor="#CCCCCC" backcolor="#CCCCCC" uuid="9bcd5cd2-f3ed-41fc-9d6c-4702a5eb2d0a"/>
                </frame>
            </band>
        </groupFooter>
    </group>
    <group name="Group2">
        <groupExpression><![CDATA[(int)($V{REPORT_COUNT}/5)]]></groupExpression>
        <groupHeader>
            <band height="30"/>
        </groupHeader>
    </group>
    <background>
        <band height="575" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="-20" y="475" width="105" height="100" backcolor="#666666" uuid="622f9467-c399-4189-9d30-50ff7d9c52a5"/>
                <textField>
                    <reportElement style="Column header" x="0" y="0" width="104" height="73" forecolor="#000000" uuid="f2a4aeb9-ff2e-44a5-9db2-bb5b0590e03a"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font size="54" isBold="true" pdfFontName="Helvetica-Bold"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="0" y="77" width="104" height="20" forecolor="#000000" uuid="96f7b50c-6c9d-441c-b9ec-e60299eac1ba"/>
                    <box leftPadding="4" rightPadding="4"/>
                    <textElement textAlignment="Center">
                        <font size="16" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <line>
                    <reportElement mode="Transparent" x="42" y="73" width="20" height="1" backcolor="#FFFFFF" uuid="2117cc39-0ba0-44ad-be80-98daa5324bc6"/>
                </line>
            </frame>
        </band>
    </background>
    <title>
        <band height="105" splitType="Stretch">
            <staticText>
                <reportElement x="222" y="35" width="280" height="36" uuid="48f86f36-c575-421a-ba54-797ace4f0917"/>
                <textElement textAlignment="Justified">
                    <font fontName="Serif" size="24"/>
                </textElement>
                <text><![CDATA[ EMPLOYEE REPORT]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="156" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="47" splitType="Stretch">
            <textField pattern="#,##0.00">
                <reportElement x="0" y="5" width="98" height="20" uuid="c623e57a-404e-4820-91f4-a7808b3d316d"/>
                <textElement>
                    <font fontName="Serif"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{EmployeeId}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="163" y="5" width="128" height="23" uuid="73bc515a-8af9-4ef0-aca5-35bb41a30892"/>
                <textFieldExpression><![CDATA[$F{EmployeeFirstName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="426" y="5" width="151" height="23" uuid="94e1ec36-478a-4761-b49a-8502057c2a08"/>
                <textFieldExpression><![CDATA[$F{EmployeeSecondName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="642" y="5" width="108" height="23" uuid="2d6f40ac-098a-4c11-a3cd-e432b1f12bb5"/>
                <textFieldExpression><![CDATA[$F{EmployeeAge}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="39" splitType="Stretch">
            <textField pattern="EEEEE dd MMMMM yyyy">
                <reportElement style="Column header" x="671" y="0" width="131" height="20" forecolor="#000000" uuid="1632c120-8789-4389-8a3e-8e68b964393d"/>
                <textElement textAlignment="Right">
                    <font size="12" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>



am using this syntax in Xml code but not working please help me

"$F{EmployeeSecondName}.equals("0") ? "--" : $F{EmployeeSecondName
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...