wood burning stoves 2.0*
The moose likes JDBC 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
Bookmark "Oracle Number(x,y)  setBigDecimal error " Watch "Oracle Number(x,y)  setBigDecimal error " New topic
Author

Oracle Number(x,y) setBigDecimal error

Jer Den
Greenhorn

Joined: Oct 16, 2003
Posts: 3
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

Joined: Jul 09, 2001
Posts: 1879

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle Number(x,y) setBigDecimal error
 
Similar Threads
preparedStatement and setxxx(1, myxxx);
WSAD 4 : oracle Number(x,y) setBigDecimal error
Long value in java
exception
oracle Number(x,y) setBigDecimal error