• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle Number(x,y) setBigDecimal error

 
Jer Den
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm mapping an oracle Number(1,4) type (float numbers) to java BigDecimal.
When i try a setBigDecimal(index, new BigDecimal(0.0001)) or someting else i get an error :
"incohrent value with precision set for the column".
I saw in the classes12.zip driver classes the oracle.sql.Number classe that wraps Number type. But for me to use setNumber i must use the OraclePreparedStatement, and so on cast my Connection to an OracleConnection to get that particular statement. The problem is that i'm using WSAD4 and it uses proxy for the OracleConnectionPoolDataSource, so i see the ibm ejs.JPhase1 interface but cannot cast it to the correct oracle connection classe...
Is there something to check when installing oracle for the setBigDecimal to work, as i cannot use the second alternative ?
tanks,
jerome
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerome,
I think your problem may not be what you think:
you create a new BigDecimal using
new BigDecimal(0.0001);
which is the equivilent of:
float f = 0.0001;
BigDecimal bd = new BigDecimal( f );
if you do a System.out.println() on either the BigDecimal or float value you will learn all about the floating point precision problem. That value in f won't be .0001 which is the value you assumed was trying to be added to the database, but more likely a value of 0.0009999997 which will throw an exception when being added to a column of size number( 1, 4 ). See past conversations on floating point precision issues.
To solve your problem, use:

When using a String to create a BigDecimal, you don't get any of the floating point precision issues, and the value remains as 0.0001 which will not violate you precision constraints on the column.
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic