Wednesday, April 1, 2009

Woes with Oracle's Jdbc Driver and BigDecimal

As other people before me noticed, Oracle seems to have issues with BigDecimals. Well, I hit one of those issues today:
  • BigDecimal.valueOf(0.000000548) became 0.000000538 in the database
  • new BigDecimal("0.000000548") became 0.000000538 in the database
  • persisting a plain String "0.000000548" worked fine however
  • new BigDecimal("0.000000458") became 0.000000448 in the database
The table column, to which the values were saved, had plenty of "scale'n'precision".
The issue occurred in Oracle's JDBC driver version 10.2.0.1.0. Luckily, after upgrading the drivers to version 10.2.0.4.0 the problems went away.

This is by itself an amazing issue - Just imagine, you were running a larger financial app. You may not even notice this subtle issue until your app is long in production. Oh well...

No comments: