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 Mon, 02 Jan 2006 10:03:37 GMT
>>>>>>>>>>>> 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.

-- 
Bernt Marius Johnsen, Database Technology Group, 
Sun Microsystems, Trondheim, Norway

Mime
View raw message