Jasper Reports中的Cast异常“无法创建报告java.lang.String无法强制转换为java.lang.Integer”

时间:2012-04-26 10:43:27

标签: java swing casting jasper-reports

我是jasper报道的新手。我用SQL Server存储过程创建了一个报告。当从Swing框架查看报告时,我收到以下异常。

 Could not create the report java.lang.String cannot be cast to java.lang.Integer

我已经使用与sql Server 2000中存储过程的定义相同的数据类型定义了报告的参数。

以下是.jrxml文件的一部分,显示存储的proc调用的参数和查询。

  <parameter name="CatID" class="java.lang.String"/>
<parameter name="Start" class="java.lang.Integer"/>
<parameter name="Stop" class="java.lang.Integer"/>
<parameter name="GoldID" class="java.lang.String"/>
<parameter name="Percentage" class="java.lang.Float"/>
<parameter name="Karat" class="java.lang.Integer"/>
<parameter name="DiaGrade" class="java.lang.Integer"/>
<parameter name="StoneGrade" class="java.lang.Integer"/>
<queryString>
    <![CDATA[{call PriceList($P{CatID},$P{Start}  ,$P{Stop},$P{GoldID},$P{Karat},$P{StoneGrade} ,$P{DiaGrade},$P{Percentage} ) }]]>
</queryString>
<field name="Design" class="java.lang.String"/>
<field name="DesignP" class="java.lang.String"/>
<field name="Model" class="java.lang.String"/>
<field name="GoldCode" class="java.lang.String"/>
<field name="CatID" class="java.lang.String"/>
<field name="OrnID" class="java.lang.Integer"/>
<field name="StoneID" class="java.lang.String"/>
<field name="ProfitPer" class="java.math.BigDecimal"/>
<field name="PlatingChg" class="java.lang.Integer"/>
<field name="SetCode" class="java.lang.String"/>
<field name="CompCost" class="java.math.BigDecimal"/>
<field name="USRate" class="java.math.BigDecimal"/>
<field name="CCost" class="java.math.BigDecimal"/>
<field name="Karat" class="java.lang.Integer"/>
<field name="GoldIDConv" class="java.lang.String"/>
<field name="StoneGrade" class="java.lang.Integer"/>
<field name="DiaGrade" class="java.lang.Integer"/>
<field name="CompCost1" class="java.math.BigDecimal"/>
<field name="GCost" class="java.math.BigDecimal"/>
<field name="ACost" class="java.math.BigDecimal"/>
<field name="SCost" class="java.math.BigDecimal"/>
<field name="Cost" class="java.math.BigDecimal"/>
<field name="Percentage" class="java.math.BigDecimal"/>
<field name="Price" class="java.math.BigDecimal"/>

我的存储过程的一部分如下

    create PROCEDURE PriceList
@CatID      char(1),
@Start      int,
@Stop       int,
@GoldID     char(1),
@Karat      tinyInt,
@StoneGrade tinyint,
@DiaGrade   tinyInt,
@Percentage numeric(6,3)

    AS
    DECLARE @mGold varchar(4),
         @TotStones int,
     @StoneGradePrice int,
     @CurrRate numeric(9,5)


Select @mGold = ''

Select @CurrRate = Rate From Currency Where Currency = 1
           Select @TotStones = 0


Select @StoneGradePrice = 0

    IF @GoldID='W'
SELECT @mGold='W'


    IF @GoldID='N'
    SELECT @mGold='WN'


   IF @GoldID='P'
   SELECT @mGold='PT'

  IF @GoldID = 'Z' 
  Select @mGold = '(2T)'
  IF @GoldID = 'Q' 
  Select @mGold = '(2P)'
  SELECT    Design=convert(varchar(20),Design+@mGold),
  DesignP=Design,Model=dbo.GetModel(Design),GoldCode=@mGold,
    CatID,
    OrnID,
    StoneID,
    ProfitPer,
    PlatingChg,
    SetCode,
            CompCost ,
    USRate=@CurrRate,
    CCost=CUS/@CurrRate
INTO #CTemp
FROM Charges a
WHERE a.CatID=@CatID
     AND OrnID BETWEEN @Start AND @Stop



   IF @GoldID='0'or @GoldID = 'Z'  or @GoldID = 'T' or @GoldID = 'Q'   or @GoldID = 'V' 
SELECT  a.CatID,
OrnID,Small=max(isnull(b.Small,0)), Medium=max(isnull(b.Medium,0)), Large=max(isnull(b.Large,0)),Karat=@Karat,GCost=SUM(GUS),KChainConv=max(KChainConv)
INTO #GTemp
FROM GoldCost a left outer  join CatGoldPlatingChg b on a.catid = b.catid  and b.GoldID = @GoldID
WHERE a.CatID=@CatID AND mKarat=@Karat
     AND OrnID BETWEEN @Start AND @Stop 
GROUP BY a.CatID,OrnID

    SELECT  a.*,
    b.Karat,
    GoldIDConv=@GoldID,
StoneGrade,
    DiaGrade,
        CompCost1=coalesce(CompCost *((100+KChainConv)/100),0),
    GCost=coalesce(GCost,0) +( coalesce((case PlatingChg when 1 then           Small        when 2 then Medium else Large end),0)/@CurrRate) ,
                       ACost=coalesce(ACost,0),
    SCost= coalesce(SCost,0),
    Cost=coalesce(CCost,0)+ coalesce(ACost,0) + coalesce(GCost,0)+ (coalesce((case PlatingChg when 1 then Small when 2 then Medium else Large end),0)/@CurrRate) +coalesce(SCost,0) + coalesce(CompCost *((100+KChainConv)/100),0),
    Percentage=@Percentage,
    Price=(convert(numeric(10,0),ceiling((((
           coalesce(CCost,0)+ coalesce(ACost,0) + coalesce(GCost,0) + (coalesce((case PlatingChg when 1 then Small when 2 then Medium else Large end),0)/@CurrRate) +coalesce(SCost,0)) * (100+ProfitPer))/100) + coalesce((CompCost) *((100+KChainConv)/100),0) )  * (100+@Percentage)/100))
FROM #CTemp a
    LEFT JOIN tempdb.#GTemp b ON (a.CatID=b.CatID AND a.OrnID=b.OrnID )
    LEFT JOIN tempdb.#ATemp d ON (a.CatID=d.CatID AND a.OrnID=d.OrnID )
    LEFT JOIN tempdb.#STemp c ON (a.CatID=c.CatID AND a.OrnID=c.OrnID  AND a.StoneID=c.StoneID)
WHERE b.GCOST IS NOT NULL AND c.SCOST IS NOT NULL
ORDER BY a.CatID,a.OrnID

1 个答案:

答案 0 :(得分:-1)

错误非常明确:

java.lang.String cannot be cast to java.lang.Integer

您正在尝试将String对象强制转换为Integer。那是不可能做到的。它们不是同一类型。因此,相应地验证输入数据和定义的字段数据类型其中一个是异常原因。