Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Sybase -->Arithmetic overflow

 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much.my issue is resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic