How to use a postgreSQL crosstab query in Jasper Reports? - sql

I'm trying to make a report in Jasper Reports using a PostgreSQL crosstab query with parameters.
Crosstab query is working when I execute it in pgAdmin 4 with static values. When I copy it into Query dialog in the report builder, and add report parameters, it doesn't work.
Versions:
PostgreSQL server 12
TIBCO Jaspersoft® Studio 6.6.0
Here's the code:
Crosstab query working in pgAdmin 4:
select
cedula,
apellidos,
nombres,
aporteIndividual,
aporteAdicional,
aporteAdicional5,
aporteSeguro,
aporteIndividual::numeric + aporteAdicional::numeric +
aporteAdicional5::numeric + aporteSeguro::numeric as total
from (
SELECT * FROM crosstab
(
'select
p.id,
a.id,
COALESCE (p.primer_apellido, '''') || '' '' ||
COALESCE (p.segundo_apellido, '''') as apellidos,
COALESCE (p.primer_nombre, '''') || '' '' ||
COALESCE (p.segundo_nombre, '''') as nombres,
p.numero_documento,
ad.tipo_aporte,
ad.valor
from
sch_participantes.participante as p,
sch_participantes.aportes as a,
sch_participantes.aporte_detalles as ad
where
p.id = a.id_participe
and a.id = ad.id_aporte
and p.filial = 1084
and p.estado = 1
and a.mes = 1
and a.anio = 2020
order by p.primer_apellido',
'select id from sch_participantes.tipo_aporte ta
order by ta.id'
)
AS
(
id_participe integer,
id_aporte integer,
apellidos text,
nombres text,
cedula text,
aporteIndividual text,
aporteAdicional text,
aporteAdicional5 text,
aporteSeguro text
)
union all
select
p.id,
null,
COALESCE (p.primer_apellido, '') || ' ' ||
COALESCE (p.segundo_apellido, '') as apellidos,
COALESCE (p.primer_nombre, '') || ' ' ||
COALESCE (p.segundo_nombre, '') as nombres,
p.numero_documento,
null,
null,
null,
null
from
sch_participantes.participante as p
where
p.id not in
(
select
a.id_participe
from
sch_participantes.aportes as a
where
a.mes = 1
and a.anio = 2020
)
and p.filial = 1084
and p.estado = 1
) as todo
order by todo.apellidos
and report code:
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="aportes-general" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="da69e8ed-7cd6-42e2-9d96-8f8d86be6137">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="205"/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="786"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="erp_pruebas_michel"/>
<property name="com.jaspersoft.studio.property.dataset.dialog.DatasetDialog.sash.w1" value="666"/>
<property name="com.jaspersoft.studio.property.dataset.dialog.DatasetDialog.sash.w2" value="320"/>
<parameter name="filial" class="java.lang.Integer" evaluationTime="Early">
<defaultValueExpression><![CDATA[1084]]></defaultValueExpression>
</parameter>
<parameter name="año" class="java.lang.Integer" evaluationTime="Early">
<defaultValueExpression><![CDATA[2020]]></defaultValueExpression>
</parameter>
<parameter name="mes" class="java.lang.Integer" evaluationTime="Early">
<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
</parameter>
<parameter name="crosstab_query" class="java.lang.String" evaluationTime="Early">
<defaultValueExpression><![CDATA["'select" +
" p.id," +
" a.id," +
" COALESCE (p.primer_apellido, '''') || '' '' ||" +
" COALESCE (p.segundo_apellido, '''') as apellidos," +
" COALESCE (p.primer_nombre, '''') || '' '' ||" +
" COALESCE (p.segundo_nombre, '''') as nombres," +
" p.numero_documento, " +
" ad.tipo_aporte," +
" ad.valor" +
" from" +
" sch_participantes.participante as p," +
" sch_participantes.aportes as a," +
" sch_participantes.aporte_detalles as ad" +
" where" +
" p.id = a.id_participe" +
" and a.id = ad.id_aporte" +
" and p.filial = " + $P{filial} +
" and p.estado = 1" +
" and a.mes = " + $P{mes} +
" and a.anio = " + $P{año} +
" order by p.primer_apellido'," +
" 'select id from sch_participantes.tipo_aporte ta" +
" order by ta.id'"]]></defaultValueExpression>
</parameter>
<queryString language="SQL">
<![CDATA[select
cedula,
apellidos,
nombres,
aporteIndividual,
aporteAdicional,
aporteAdicional5,
aporteSeguro,
aporteIndividual::numeric + aporteAdicional::numeric +
aporteAdicional5::numeric + aporteSeguro::numeric as total
from (
SELECT * FROM crosstab ($P{crosstab_query})
AS
(
id_participe integer,
id_aporte integer,
apellidos text,
nombres text,
cedula text,
aporteIndividual text,
aporteAdicional text,
aporteAdicional5 text,
aporteSeguro text
)
union all
select
p.id,
null,
COALESCE (p.primer_apellido, '') || ' ' ||
COALESCE (p.segundo_apellido, '') as apellidos,
COALESCE (p.primer_nombre, '') || ' ' ||
COALESCE (p.segundo_nombre, '') as nombres,
p.numero_documento,
null,
null,
null,
null
from
sch_participantes.participante as p
where
p.id not in
(
select
a.id_participe
from
sch_participantes.aportes as a
where
a.mes = $P{mes}
and a.anio = $P{año}
)
and p.filial = $P{filial}
and p.estado = 1
) as todo
order by todo.apellidos]]>
</queryString>
<field name="cedula" class="java.lang.String"/>
<field name="apellidos" class="java.lang.String"/>
<field name="nombres" class="java.lang.String"/>
<field name="aporteIndividual" class="java.math.BigDecimal"/>
<field name="aporteAdicional" class="java.math.BigDecimal"/>
<field name="aporteAdicional5" class="java.math.BigDecimal"/>
<field name="aporteSeguro" class="java.math.BigDecimal"/>
<field name="total" class="java.math.BigDecimal"/>
<background>
<band/>
</background>
<title>
<band height="72">
<frame>
<reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="0dc47f7a-395a-4b8d-87b4-e927fca8fa61"/>
<staticText>
<reportElement x="20" y="20" width="410" height="30" forecolor="#FFFFFF" uuid="3c6488eb-bfbc-4fb6-b9b2-3637a1cf0c9d"/>
<textElement>
<font size="19" isBold="true"/>
</textElement>
<text><![CDATA[Reporte general de aportes]]></text>
</staticText>
<textField>
<reportElement x="20" y="50" width="300" height="30" forecolor="#FFFFFF" uuid="4a131c99-d637-4199-9335-493f0e7a7750"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA["Período:" + $P{mes} + "-" + $P{año}]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
<pageHeader>
<band height="13"/>
</pageHeader>
<columnHeader>
<band height="18">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
<staticText>
<reportElement x="0" y="0" width="50" height="18" uuid="4d23b483-a6f5-44f1-b4b0-e0c92d8736b0">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fdf238bc-d6fa-41f7-a846-a09be881e2a8"/>
</reportElement>
<text><![CDATA[cedula]]></text>
</staticText>
<staticText>
<reportElement x="50" y="0" width="130" height="18" uuid="b2c90d08-f6a7-441c-92c3-3487aed4a04f">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="87c434fd-7660-4c3e-8ca4-97bb9499349b"/>
</reportElement>
<text><![CDATA[apellidos]]></text>
</staticText>
<staticText>
<reportElement x="180" y="0" width="120" height="18" uuid="4aca3646-0e0e-4253-83f3-7903cb60b048">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="289c8d74-6077-45d8-9373-c238a4598284"/>
</reportElement>
<text><![CDATA[nombres]]></text>
</staticText>
<staticText>
<reportElement x="300" y="0" width="50" height="18" uuid="3e268eea-8ecb-4fb1-8bfe-6f99f39caccb">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="8d1cedc0-4fd2-4f06-8725-b17630f08437"/>
</reportElement>
<text><![CDATA[aporteIndividual]]></text>
</staticText>
<staticText>
<reportElement x="350" y="0" width="50" height="18" uuid="5f5e3710-7eef-48c5-a962-6120bb9fa67b">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fa8014b3-1b03-4443-bf80-167703b8f1cb"/>
</reportElement>
<text><![CDATA[aporteAdicional]]></text>
</staticText>
<staticText>
<reportElement x="400" y="0" width="50" height="18" uuid="00653733-6788-45b6-ab57-d37d12293a6d">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="d066fefc-d2fb-49b9-bde1-f706ea220cb9"/>
</reportElement>
<text><![CDATA[aporteAdicional5]]></text>
</staticText>
<staticText>
<reportElement x="450" y="0" width="50" height="18" uuid="cf37f752-5ba2-4950-8200-099943713cd7">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="e434b3c8-20bc-4631-b59b-a4939675978f"/>
</reportElement>
<text><![CDATA[aporteSeguro]]></text>
</staticText>
<staticText>
<reportElement x="500" y="0" width="50" height="18" uuid="623db75c-ff28-4aab-8fc3-190f479cd8c5">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5cd0ec9d-c45b-4e7b-9fbc-2bb616521f0e"/>
</reportElement>
<text><![CDATA[total]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
<textField>
<reportElement x="0" y="0" width="50" height="30" uuid="2a352a63-f1fe-4a2e-bb74-937d2e3f335b">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fdf238bc-d6fa-41f7-a846-a09be881e2a8"/>
</reportElement>
<textFieldExpression><![CDATA[$F{cedula}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="50" y="0" width="130" height="30" uuid="970896d3-426b-41f2-b097-784d83a2e172">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="87c434fd-7660-4c3e-8ca4-97bb9499349b"/>
</reportElement>
<textFieldExpression><![CDATA[$F{apellidos}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="120" height="30" uuid="0c2e4d66-7faa-4baa-a77a-dfbe60dfe466">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="289c8d74-6077-45d8-9373-c238a4598284"/>
</reportElement>
<textFieldExpression><![CDATA[$F{nombres}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="50" height="30" uuid="0c6e4a8e-5b0e-4a07-9d73-282781817c95">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="8d1cedc0-4fd2-4f06-8725-b17630f08437"/>
</reportElement>
<textFieldExpression><![CDATA[$F{aporteIndividual}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="350" y="0" width="50" height="30" uuid="d2af8ebf-cbc9-407e-8dbe-f1af49525966">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fa8014b3-1b03-4443-bf80-167703b8f1cb"/>
</reportElement>
<textFieldExpression><![CDATA[$F{aporteAdicional}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="400" y="0" width="50" height="30" uuid="a78a3c65-c069-447d-a3ae-84087e3f4977">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="d066fefc-d2fb-49b9-bde1-f706ea220cb9"/>
</reportElement>
<textFieldExpression><![CDATA[$F{aporteAdicional5}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="450" y="0" width="50" height="30" uuid="5f22b066-53b8-47dd-b2c9-bb026eb69dae">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="e434b3c8-20bc-4631-b59b-a4939675978f"/>
</reportElement>
<textFieldExpression><![CDATA[$F{aporteSeguro}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="500" y="0" width="50" height="30" uuid="1f698fc0-da4d-4aa9-b21e-6ba74dfe8df0">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5cd0ec9d-c45b-4e7b-9fbc-2bb616521f0e"/>
</reportElement>
<textFieldExpression><![CDATA[$F{total}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="17">
<textField>
<reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6" uuid="0b71f3fa-21ce-4aa4-8fbc-84c015c403e3"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6" uuid="837ccbf7-57ea-4894-a13f-415d2472630f"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="4" width="100" height="13" uuid="ae716933-1e7e-4a7c-b470-d58ad1afcd72"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="47">
<staticText>
<reportElement x="270" y="0" width="100" height="30" uuid="5042bbb1-6dc0-4b69-a4f6-49f75dc42a25"/>
<text><![CDATA[Total Aportes]]></text>
</staticText>
</band>
</summary>
</jasperReport>
When I execute preview, I get this syntax error:
Caused by: org.postgresql.util.PSQLException: ERROR: error de sintaxis
en o cerca de «'select p.id, a.id, COALESCE (p.primer_apellido,
'''') || '' '' || COALESCE (p.segundo_apellido, '''') as
apellidos, COALESCE (p.primer_nombre, '''') || '' '' || COALESCE
(p.segundo_nombre, '''') as nombres, p.numero_documento,
ad.tipo_aporte, ad.valor from sch_participantes.participante as
p, sch_participantes.aportes as a,
sch_participantes.aporte_detalles as ad where p.id = a.id_participe
and a.id = ad.id_aporte and p.filial = 1084 and p.estado = 1
and a.mes = 1 and a.anio = 2020 order by p.primer_apellido'» at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273) at
net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:310)
... 6 more
For testing purposes, I replaced the SQL query with a fixed crosstab inner query like this:
<queryString language="SQL">
<![CDATA[select
cedula,
apellidos,
nombres,
aporteIndividual,
aporteAdicional,
aporteAdicional5,
aporteSeguro,
aporteIndividual::numeric + aporteAdicional::numeric +
aporteAdicional5::numeric + aporteSeguro::numeric as total
from (
SELECT * FROM crosstab (
'select
p.id,
a.id,
COALESCE (p.primer_apellido, '''') || '' '' ||
COALESCE (p.segundo_apellido, '''') as apellidos,
COALESCE (p.primer_nombre, '''') || '' '' ||
COALESCE (p.segundo_nombre, '''') as nombres,
p.numero_documento,
ad.tipo_aporte,
ad.valor
from
sch_participantes.participante as p,
sch_participantes.aportes as a,
sch_participantes.aporte_detalles as ad
where
p.id = a.id_participe
and a.id = ad.id_aporte
and p.filial = 1084
and p.estado = 1
and a.mes = 1
and a.anio = 2020
order by p.primer_apellido',
'select id from sch_participantes.tipo_aporte ta
order by ta.id'
)
AS
(
id_participe integer,
id_aporte integer,
apellidos text,
nombres text,
cedula text,
aporteIndividual text,
aporteAdicional text,
aporteAdicional5 text,
aporteSeguro text
)
union all
select
p.id,
null,
COALESCE (p.primer_apellido, '') || ' ' ||
COALESCE (p.segundo_apellido, '') as apellidos,
COALESCE (p.primer_nombre, '') || ' ' ||
COALESCE (p.segundo_nombre, '') as nombres,
p.numero_documento,
null,
null,
null,
null
from
sch_participantes.participante as p
where
p.id not in
(
select
a.id_participe
from
sch_participantes.aportes as a
where
a.mes = $P{mes}
and a.anio = $P{año}
)
and p.filial = $P{filial}
and p.estado = 1
) as todo
order by todo.apellidos]]>
</queryString>
and the report preview executed well.
Any advice is truly appreciated.

JasperReports translates $P{..} in report queries to JDBC prepared statement parameters. That is, if you have WHERE column = $P{..} in the report query, the report will run WHERE column = ? as a prepared statement with the report parameter value sent as statement parameter.
Prepared statement parameters stand for single values in the query, so crosstab($P{..}) will not work, even if the parameter values contains a comma. What might work is crosstab($P{first_query}, $P{second_query}), just note that prepared statement parameters are provided as raw values so you should not enclose the values in quotes or escape quotes inside the values.
But if you just want to textually insert the parameter value in the query, you can use $P!{..} instead of $P{..}. Since the parameter value in your report looks like a query fragment, using SELECT * FROM crosstab ($P!{crosstab_query}) in the report query should work.

Related

Incorrect syntax near 'nvarchar'. I get this error whenever trying to update a field on a database table using a grid view

This is my ASP.net code the query gets all details from the customer table and then in the grid view the user is allowed to edit the fields. Whenever i click update it throws that error then. When researching the problem i seen alot of people where saying about using spaces and [] but i tried the code with no spaces and no brackets but still get the same error. I also tried adding a # for the parameters in the gridview Please Help.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:BookConnString %>" DeleteCommand="DELETE FROM Customer WHERE Email = #original_Email AND (([First Name] = #original_First_Name) OR ([First Name] IS NULL AND #original_First_Name IS NULL)) AND (([Surname] = #original_Surname) OR ([Surname] IS NULL AND #original_Surname IS NULL)) AND (([Address] = #original_Address) OR ([Address] IS NULL AND #original_Address IS NULL)) AND (([Postcode] = #original_Postcode) OR ([Postcode] IS NULL AND #original_Postcode IS NULL)) AND (([Gender] = #original_Gender) OR ([Gender] IS NULL AND #original_Gender IS NULL))" InsertCommand="INSERT INTO Customer ([Email], [First Name], [Surname], [Address], [Postcode], [Gender]) VALUES (#Email, #First_Name, #Surname, #Address, #Postcode, #Gender)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM Customer" UpdateCommand="UPDATE Customer SET [First Name] = #First_Name, [Surname] = #Surname, [Address] = #Address, [Postcode] = #Postcode, [Gender] = #Gender WHERE [Email] = #original_Email AND (([First Name] = #original_First_Name) OR ([First Name] IS NULL AND #original_First_Name IS NULL)) AND (([Surname] = #original_Surname) OR ([Surname] IS NULL AND #original_Surname IS NULL)) AND (([Address] = #original_Address) OR ([Address] IS NULL AND #original_Address IS NULL)) AND (([Postcode] = #original_Postcode) OR ([Postcode] IS NULL AND #original_Postcode IS NULL)) AND (([Gender] = #original_Gender) OR ([Gender] IS NULL AND #original_Gender IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_First_Name" Type="String" />
<asp:Parameter Name="original_Surname" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
<asp:Parameter Name="original_Postcode" Type="String" />
<asp:Parameter Name="original_Gender" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="First_Name" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Postcode" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="First_Name" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Postcode" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_First_Name" Type="String" />
<asp:Parameter Name="original_Surname" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
<asp:Parameter Name="original_Postcode" Type="String" />
<asp:Parameter Name="original_Gender" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</p>
<p class="auto-style4">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Email" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" SortExpression="Email" />
<asp:BoundField DataField="First Name" HeaderText="First Name" SortExpression="First Name" />
<asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Postcode" HeaderText="Postcode" SortExpression="Postcode" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
</Columns>
</asp:GridView>
The problem originated from these lines:
-- first problem
SELECT * FROM Customer
<%-- second problem --%>
<asp:BoundField DataField="First Name" HeaderText="First Name" SortExpression="First Name" />
First, by using SELECT * in first query makes all table columns (including First Name with spaces) selected, and possibly causing syntax error when binding with BoundField. You need to change query with alias (using AS keyword) for column name with spaces like this:
SelectCommand="SELECT [First Name] AS First_Name, Surname, Address, Postcode, Gender, Email FROM Customer"
Note that by using column alias, you can't use * anymore and need to include all column names to bind properly with GridView.
Second, the DataField (and SortExpression) accepts column name with same rule as identifier names in code behind, hence First Name is not accepted and need to use underscore instead:
<asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name" />
As alternative to column alias, try to change First Name column as First_Name (or FirstName if Pascal case preferred) in database table, query and DataField name as in example below (no need to use square brackets surrounding column names):
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BookConnString %>"
DeleteCommand="DELETE FROM Customer WHERE Email = #original_Email AND ((First_Name = #original_First_Name) ...)"
SelectCommand="SELECT * FROM Customer"
UpdateCommand="UPDATE Customer SET First_Name = #First_Name, Surname = #Surname, ... WHERE Email = #original_Email AND ((First_Name = #original_First_Name) OR (First_Name IS NULL ...) ...)">
...
</asp:SqlDataSource>
Similar issue:
Incorrect syntax near nvarchar in GridView

How to hide page header band on last page

I think I am having a problem with evaluation time. In this example, you see the variable $P{REPORT_PARAMETERS_MAP}.get("LastPageNumber") reflecting the last page correctly; it updates correctly. But when I use it for the "printWhenExpression" of a detail band field (experiment) or for the page header band (my goal) it does not work.
I am using "page" evaluation time throughout which seems to work for the variable itself. But the printWhenExpressions are not working using this variable.
Here is my xml file :
<?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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString>
<![CDATA[select * from users]]>
</queryString>
<field name="userName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<pageHeader>
<band height="23" splitType="Stretch">
<textField evaluationTime="Page">
<reportElement x="120" y="0" width="238" height="20">
<printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - page header"]]></textFieldExpression>
</textField>
<textField evaluationTime="Page">
<reportElement x="380" y="0" width="175" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="2" y="2" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["Page header"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<detail>
<band height="21" splitType="Stretch">
<textField evaluationTime="Page">
<reportElement x="381" y="0" width="174" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{userName}]]></textFieldExpression>
</textField>
<textField evaluationTime="Page">
<reportElement x="119" y="0" width="191" height="20">
<printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - detail"]]></textFieldExpression>
</textField>
</band>
</detail>
<lastPageFooter>
<band height="50">
<line>
<reportElement x="188" y="21" width="100" height="1">
<printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",
$V{PAGE_NUMBER}))]]></printWhenExpression>
</reportElement>
</line>
<textField evaluationTime="Page">
<reportElement x="380" y="2" width="174" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
.get("LastPageNumber"))]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>
My solution was to make two reports (one for the last page) and then join them (jasperPrints) using the array list option for he jasper exporter:
List jasperPrintList = new ArrayList();
JasperPrint jasperPrint1 =
JasperFillManager.fillReport(
jasperReport1,
parameters,
c
);
JasperPrint jasperPrint2 =
JasperFillManager.fillReport(
jasperReport2,
parameters,
c
);
jasperPrintList.add(jasperPrint1);
jasperPrintList.add(jasperPrint2);
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream byte_report = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "test_report_name");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, byte_report);
exporter.exportReport();

How to add bullet point in TextField

I want to add bullet point to my static text and to a text field, i added style tag to the jrxml but it didn't work for me :
Here's the example :
TextField :
<textField isBlankWhenNull="true">
<reportElement uuid="cfd514bc-d1c5-4369-b10d-71042b046e37" x="11" y="0" width="400" height="12"/>
<textElement/>
<textFieldExpression><![CDATA[<style size="40">.</style>$F{LMSG}]]></textFieldExpression>
</textField>
StaticText:
<staticText>
<reportElement uuid="c1485aba-09a4-4c7b-9106-0893341f1368" x="44" y="107" width="309" height="15"/>
<textElement>
<font size="9"/>
</textElement>
<text><![CDATA[<style size="40">.</style>Je déduis cet avoir de ma commande]]></text>
</staticText>
You can use styled markup.
Try to use <li> tag.
The sample
The jrxml file:
<?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="bullet_sample" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="aa7ced41-689a-4b8d-94aa-ee79c243a7a8">
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement uuid="bf39def6-a3a7-4fa1-9e99-e488b3567974" x="159" y="31" width="100" height="20"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA["<li>Text with bullet</li>"]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
The result will be (via preview in iReport):
In case using field, the right expression will be:
<textField>
<reportElement x="171" y="0" width="100" height="20"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA["<li>" + $F{fieldName} + "</li>"]]></textFieldExpression>
</textField>
Note:
You can find more info about styled text in Style a text field in JasperReports post and in Styled Text sample
I used the <li> tag, but it introduced padding which did not look good. So, I used "\u2022" which gives a round symbol like
<textFieldExpression><![CDATA["\u2022 Line1\n\u2022 Line2"]]></textFieldExpression>
So, this looks much cleaner

How to get the workflow authentication to work in Aviarc

We are trying to roll out authentication into my app and it’s not working for us.
We have set up the Current Authority and Current Authorizer and have even set the login query to be just select ‘a’ so we are guaranteed to get a result set.
We have copied the Login workflow to workflows/system directory.
It doesn’t look like it’s even trying to run the login query.
start.xml workflow:
<workflow>
<authenticate error-screen="login-error" dataset="login">
<show-screen name="login" />
</authenticate>
<call-workflow name="home"/>
</workflow>
login.xml screen:
<screen xmlns:action="urn:aviarc:widget:com.aviarc.toronto.widget.core.action:1"
xmlns:app="urn:aviarc:widget:application">
<group-box visible="y" left="10" right="4" top="10" bottom="4" class="blue">
<image height="80" width="245" left="10" top="5" class="mfcologo" />
<line height="5" left="0" right="0" top="120" class="myerblue" />
<text-static visible="y" left="74" top="151" width="80" height="20" text="User name:" />
<text-static visible="y" left="234" top="151" width="80" height="20" text="Password:" />
<text-edit name="username" left="74" top="182" width="100" height="20" field="login.user_name" />
<text-edit name="password" left="234" top="182" width="100" height="20" field="login.user_password" datatype="password" />
<button left="376" top="182" width="60" height="20" label="Login" action="Next"/>
</group-box>
</screen>
system/Login.xml workflow:
<workflow xmlns:au-security="urn:aviarc:xmlcommand:au.com.aviarc.xmlcommand.security">
<au-security:hash-text text="{$login.user_password}" result-field="login.hashed-password" />
<dataset name="cslogin" databroker="loginqry" query="get-all">
<param name="username" value="{$login.user_name}" />
<param name="password" value="{$login.hashed-password}" />
</dataset>
<if test="dataset-empty" value1="cslogin">
<then>
<set-field field="login.authenticated" value="n"/>
</then>
<else>
<set-field field="login.authenticated" value="y"/>
</else>
</if>
</workflow>
The Workflow authentication requires "username" field to be populated prior to entering it, otherwise the authentication would fail immediately and login error screen will be displayed.
In your example it is fairly easy to fix, changing the line in login.xml screen from:
<text-edit name="username" left="74" top="182" width="100" height="20" field="login.user_name" />
to be:
<text-edit name="username" left="74" top="182" width="100" height="20" field="login.username" />
and updating reference to it in the system/Login workflow.

JasperReports: how to tell if a field is pushed onto next page

I am generating a report with contacts that span across different pages.
Previously I had isSplitAllowed set to "true".
But I don't want a contact to split across different pages.
So I set it to "false", the layout of the report looked much better. However it introduced a new problem:
In my header, I print the name of the first person and last person of the page.
When a contact gets pushed to the next page, it is still processed in the current page.
So let's say Bob was supposed to be at the bottom of the first page. But to prevent it from splitting, Bob is now the first element in the second page.
However on the header of my first page I still have Alice...Bob (where Alice is the first person of the first page).
And on my second page I still have Brenda...Doug (Where Brenda is now the 2nd person of the 2nd page, and Doug last person of 2nd page).
My output at the header is
[$V{pageFirstItem} + "..." + $V{pageLastItem}]]>
where pageFirstItem is:
<variable name="pageFirstItem" class="java.lang.String" resetType="Page" calculation="First">
<variableExpression><![CDATA[$F{lastName}]]></variableExpression>
<initialValueExpression><![CDATA[$F{lastName}]]></initialValueExpression>
</variable>
and pageLastItem is:
<variable name="pageLastItem" class="java.lang.String" resetType="Report" calculation="Nothing">
<variableExpression><![CDATA[$F{lastName}]]></variableExpression>
I've attached a working sample workaround below based on iReport 3.0.5. You can test it by running it with isSplitAllowed enabled and disabled. The problem is that a detail record is processed on page i even if isSplitAllowed="false" forces the record to be printed on page i+1.
Summary:
For firstItem, no calculation is needed. Just put the Name field in the header.
For lastItem, you need to save the Name processed using a variable, prop, of type java.util.Property. This is done by putting a dummy, height of 0, textField in the detail section with the following value prop.setProperty("lastSavedName", $F{Name}). This textField makes sure that the name is saved only after it is printed.
Then put the value from prop, prop.getProperty("lastSavedName"), in the header with the evaluationTime="Page".
<?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="Untitled_report_1"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isFloatColumnFooter="true"
isTitleNewPage="false"
isSummaryNewPage="true">
<property name="ireport.zoom" value="1.0" />
<property name="ireport.x" value="0" />
<property name="ireport.y" value="0" />
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<queryString><![CDATA[select 1 as id, 'Name 1' as name from dual union all
select 2 as id, 'Name 2' as name from dual union all
select 3 as id, 'Name 3' as name from dual union all
select 4 as id, 'Name 4' as name from dual union all
select 5 as id, 'Name 5' as name from dual union all
select 6 as id, 'Name 6' as name from dual union all
select 7 as id, 'Name 7' as name from dual union all
select 8 as id, 'Name 8' as name from dual union all
select 9 as id, 'Name 9' as name from dual union all
select 10 as id, 'Name 10' as name from dual union all
select 11 as id, 'Name 11' as name from dual union all
select 12 as id, 'Name 12' as name from dual union all
select 13 as id, 'Name 13' as name from dual union all
select 14 as id, 'Name 14' as name from dual union all
select 15 as id, 'Name 15' as name from dual union all
select 16 as id, 'Name 16' as name from dual union all
select 17 as id, 'Name 17' as name from dual union all
select 18 as id, 'Name 18' as name from dual union all
select 19 as id, 'Name 19' as name from dual union all
select 20 as id, 'Name 20' as name from dual union all
select 21 as id, 'Name 21' as name from dual union all
select 22 as id, 'Name 22' as name from dual union all
select 23 as id, 'Name 23' as name from dual union all
select 24 as id, 'Name 24' as name from dual union all
select 25 as id, 'Name 25' as name from dual union all
select 26 as id, 'Name 26' as name from dual union all
select 27 as id, 'Name 27' as name from dual union all
select 28 as id, 'Name 28' as name from dual]]></queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="NAME" class="java.lang.String"/>
<variable name="prop" class="java.util.Properties" resetType="Report" calculation="System">
<initialValueExpression><![CDATA[new Properties()]]></initialValueExpression>
</variable>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="0" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="16" isSplitAllowed="true" >
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="96"
height="16"
key="textField-3"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["First " + $F{ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Page" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="96"
y="0"
width="100"
height="16"
key="textField-4"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Last " + $V{prop}.getProperty("abcd")]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="20" isSplitAllowed="true" >
<staticText>
<reportElement
x="0"
y="0"
width="96"
height="20"
key="staticText-2"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[CustomerName]]></text>
</staticText>
<staticText>
<reportElement
x="96"
y="0"
width="100"
height="20"
key="staticText-3"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[Workorderid]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="96"
height="18"
key="textField"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}+"This\nwill\ncause\na\nsplit."]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="##0.00" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="96"
y="0"
width="100"
height="18"
key="textField"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Band" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="196"
y="0"
width="339"
height="0"
key="textField-5"
isRemoveLineWhenBlank="true"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$V{prop}.setProperty("abcd", String.valueOf($F{ID}))]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="0" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>