On Wednesday 04 January 2006 6:11 am, Bernt M. Johnsen wrote: Uhm, Sorry to top post byt Bernt is right. This is not a bug and IMHO there shouldn't be a JIRA issue opened.
What you are seeing is correct. Check out : "http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html" You have a couple of methods for PreparedStatement.setObject(). You chose the wrong one. You do need to set the scale. The method that you are using assumes the scale to be 0. (This is per the Java Docs provided by Sun) But hey, what do I know? I just happend to take the time to RTFM. ;-) Cheers! -G > >>>>>>>>>>>> Thomas Dudziak wrote (2006-01-03 17:18:02): > > > > On 1/2/06, Bernt M. Johnsen <[EMAIL PROTECTED]> 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. -- -- Michael Segel Principal Michael Segel Consulting Corp. [EMAIL PROTECTED] (312) 952-8175 [mobile]
