ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shilpa <shilpa.prad...@judiciary.state.nj.us>
Subject Re: QueryForObject returns wrong data
Date Thu, 28 Jul 2005 13:02:04 GMT
Prashanth Sukumaran <prashanthsukumaran <at> yahoo.com> writes:

> 
> Hi Jeff,
> 
> I don't know how the scale would work.
> 
> As per jdk 1.4 there are 4 constructors to create BigDecimal.  The first two 
use biginteger, i
> think this will not be a case at BigInteger would not be mapped to Decimal 
type field.
> 
> The other two use double or string.  In both cases the value is 90.94.
> 
> 		BigDecimal bd = new BigDecimal("90.94");
> 		double dble = 90.94;
> 		BigDecimal bd2 = new BigDecimal(dble);
> 		System.out.println("The big decimal value is "+bd);
> 		System.out.println("The big decimal integer value is "+bd2);
> 
> The big decimal value is 90.94
> The big decimal integer value is 
90.93999999999999772626324556767940521240234375
> 
> i tried setting the scale for example 
> 
> 		bd.setScale(1);
> 
> Ofcourse there are two decimals but i tried with setScale(1) you would get a 
>    java.lang.ArithmeticException: Rounding necessary
> 	at java.math.BigDecimal.divide(BigDecimal.java:465)
> 	at java.math.BigDecimal.setScale(BigDecimal.java:699)
> 
> with setScale(2).  Java gives the output as 90.94 which is same without scale.
> 
> Shilpa are you sure there is no typo or some problem in the data flow.  Are 
you coping data from
> one bean to another.  Just for kicks why don't you create another field which 
is a varchar have
> the data as string 90.94 and in the result map have javaType as BigDecimal 
and dataType as
> Varchar.
> 
> Also paste the java bean code here and the dao class code that is calling it?
> 
> Rgds
> 
> Prashanth.
> 
> --- Jeff Butler <dhscn06 <at> cstone.dhs.state.il.us> wrote:
> 
> > Shilpa,
> > 
> > I cannot get this to fail using DB2 version 8.2, fixpack 9a.  I have
> > used both the type 2 and type 4 drivers, and I get the correct results
> > in each case (even calling the SP multiple times - works every time).
> > 
> > I still believe this is something that should be changed in iBATIS -
> > just to make sure we are following the JDBC spec as closely as possible.
> >  But it looks like the DB2 version 8 drivers are fairly robust.
> > 
> > Would you please provide some configuration details:
> > 
> > 1. DB2 Server Version and platform
> > 2. DB2 Client Version
> > 3. Type of driver you are using
> > 
> > I don't have easy access to DB2 version 7 anymore for testing, but that
> > might be part of the problem if you are still on that version.  The
> > version 7 driver had some, shall we say, peculiarities.
> > 
> > Jeff Butler
> > 
> > 
> 
> 		
> ____________________________________________________
> Start your day with Yahoo! - make it your home page 
> http://www.yahoo.com/r/hs 
> 
> 

Ok, I will try this varchar option. 

But there is no typo, as following is a direct JDBC call, and I am prinitng 
values right there (without assigning it to any bean).

CallableStatement cs;
cs =con.prepareCall("{call DBAD.CFSP1501
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");

cs.registerOutParameter(7,Types.DECIMAL); // as This field is creating problem

cs.executeUpdate(); or cs.executeQuery(); // tried both

// and I am printing right there, in the same method.

System.out.println("cs.getBigDecimal(7)" + cs.getBigDecimal(7));

This is returning me correct data once (first time), but only 99 for rest.

But if I do:

cs.registerOutParameter(7,Types.DECIMAL,2);//works fine.

There is no iBatis code in above statments (pure JDBC).

And also as Jeff mentioned, I am using DB2 7.1 on mainframe. So Db2 version may 
be a problem. 

Thanks,
shilpa




Mime
View raw message