aspose file tools*
The moose likes Java in General and the fly likes Java Sybase -->Arithmetic overflow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Sybase -->Arithmetic overflow " Watch "Java Sybase -->Arithmetic overflow " New topic
Author

Java Sybase -->Arithmetic overflow

Vinny Menon
Ranch Hand

Joined: Jan 10, 2006
Posts: 62

Hi fellow ranchers,
my application tries to insert data into sybase database.I use the JDBC preparedstatement.It is a simple insert query.
One of the fields is field1 which is defined as Numeric(38,14) in database.But i get the error when i call the preparedstatement.executeUpdate();
-----------------------------------------------------------------

-----------------------------------------------------------------
The value passed to the preparedstatement is
preparedStatement.setDouble( 0,myBean.getField().doubleValue());
and it is 6778.68 !!!

also i use a convert function in the stored procedure when performing the insertion in the database
convert(numeric(38,14),@field1)
------------------------------------------------
can someone please suggest how to handle this situation
thanks in advance
cheers
vinny m
[ June 17, 2008: Message edited by: Vinny Menon ]

Regards,Vinny M.
proud Fan of European Champion CHELSEA FC
"If you don't see the bug where you're looking, perhaps you're looking in the wrong place" -James Gosling
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
You should know that in SQL a "float" is maintained in floating-point arithmetic (as in Java, but in SQL I think it is 64 bits), and that floating-point arithmetic is imprecise. Go through the search facility on JavaRanch, and also this FAQ (no 20) and you will find lots of examples.

In SQL a "numeric" is stored as a String; obviously when the values are converted there is rounding "up."
Vinny Menon
Ranch Hand

Joined: Jan 10, 2006
Posts: 62

Thanks very much.my issue is resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Sybase -->Arithmetic overflow