db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernt M. Johnsen" <Bernt.John...@Sun.COM>
Subject Re: setObject(idx, bigDecimal, Types.NUMERIC); doesn't work ?
Date Wed, 04 Jan 2006 12:11:48 GMT
>>>>>>>>>>>> Thomas Dudziak wrote (2006-01-03 17:18:02):
> On 1/2/06, Bernt M. Johnsen <Bernt.Johnsen@sun.com> wrote:
> > >>>>>>>>>>>> Thomas Dudziak wrote (2005-12-25
16:18:14):
> > > When executing this code snippet:
> > >
> > >
> > > Statement  stmt = conn.createStatement();
> > >
> > > stmt.executeUpdate("CREATE TABLE test (\n"+
> > >                    "    pk INTEGER NOT NULL,\n"+
> > >                    "    value NUMERIC(15,7) NOT NULL,\n"+
> > >                    "    PRIMARY KEY (pk)\n"+
> > >                    ")");
> > > stmt.close();
> > >
> > > PreparedStatement pstmt = conn.prepareStatement("INSERT INTO test (pk,
> > > value) VALUEs (?, ?)");
> > >
> > > pstmt.setInt(1, 1);>
> > > pstmt.setObject(2, new BigDecimal("0.01"), Types.NUMERIC);
> >
> > > pstmt.execute();
> > > pstmt.close();
> > >
> > > conn.close();
> > >
> > >
> > > the resulting value in the database is 0e-7, not 1e-2 as I would expect.
> > > When changing that to
> > >
> > >
> > > pstmt.setBigDecimal(2, new BigDecimal("0.01"));
> > >
> > >
> > > it works though.
> > > Did I make a mistake or is this a bug ?
> >
> > I think you have found a bug. I experimented a bit and found that it
> > works for values >= 1.0 but the result will be 0 for values < 1.0.
> >
> >       pstmt.setObject(2, new BigDecimal("1.0"), Types.NUMERIC);
> >
> > works perefectly ok while
> >
> >       pstmt.setObject(2, new BigDecimal("0.999999999"), Types.NUMERIC);
> >
> > is errouneous.

BUT: pstmt.setObject(2, new BigDecimal("0.999999999"), Types.NUMERIC, 7);

(giving the scale) does work.
-- 
Bernt Marius Johnsen, Database Technology Group, 
Staff Engineer, Technical Lead Derby/Java DB
Sun Microsystems, Trondheim, Norway

Mime
View raw message