File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Oracle Number(x,y)  setBigDecimal error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Oracle Number(x,y)  setBigDecimal error " Watch "Oracle Number(x,y)  setBigDecimal error " New topic

Oracle Number(x,y) setBigDecimal error

Jer Den

Joined: Oct 16, 2003
Posts: 3
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 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 ?
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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.
I agree. Here's the link:
subject: Oracle Number(x,y) setBigDecimal error
It's not a secret anymore!